From f241d694258fd1c501249a09a00930b86be35d51 Mon Sep 17 00:00:00 2001 From: Rob Loranger Date: Mon, 12 Aug 2019 14:12:35 -0700 Subject: [PATCH] reduce GetPinnedPosts calls to single line --- collections.go | 12 ++---------- posts.go | 6 +----- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/collections.go b/collections.go index 7eb3741..adf89d4 100644 --- a/collections.go +++ b/collections.go @@ -783,11 +783,7 @@ func handleViewCollection(app *App, w http.ResponseWriter, r *http.Request) erro // Add more data // TODO: fix this mess of collections inside collections - if isOwner { - displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, true) - } else { - displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, false) - } + displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, isOwner) err = templates["collection"].ExecuteTemplate(w, "collection", displayPage) if err != nil { @@ -884,11 +880,7 @@ func handleViewCollectionTag(app *App, w http.ResponseWriter, r *http.Request) e coll.Owner = displayPage.Owner // Add more data // TODO: fix this mess of collections inside collections - if isOwner { - displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, true) - } else { - displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, false) - } + displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, isOwner) err = templates["collection-tags"].ExecuteTemplate(w, "collection-tags", displayPage) if err != nil { diff --git a/posts.go b/posts.go index edef6fb..a1383fa 100644 --- a/posts.go +++ b/posts.go @@ -1380,11 +1380,7 @@ Are you sure it was ever here?`, IsCustomDomain: cr.isCustomDomain, IsFound: postFound, } - if p.IsOwner { - tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll, true) - } else { - tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll, false) - } + tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll, p.IsOwner) tp.IsPinned = len(*tp.PinnedPosts) > 0 && PostsContains(tp.PinnedPosts, p) if !postFound {