From 5eaa8c8c89ab1a1beaaab40609f48112b98793b1 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sun, 1 Mar 2020 09:15:48 +1000 Subject: [PATCH] optimise away this string for non-admins optimise away redundant parentID column on ViewForum --- routes/common.go | 10 +++++----- routes/forum.go | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/routes/common.go b/routes/common.go index 04b69618..7df1c58e 100644 --- a/routes/common.go +++ b/routes/common.go @@ -137,11 +137,11 @@ func renderTemplate3(tmplName, hookName string, w http.ResponseWriter, r *http.R FootHeaders(w, h) if h.Zone != "error" { - since := time.Duration(uutils.Nanotime() - h.StartedAt) - //if h.CurrentUser.IsAdmin { - h.Elapsed1 = since.String() - //} - co.PerfCounter.Push(since/*, false*/) + since := time.Duration(uutils.Nanotime() - h.StartedAt) + if h.CurrentUser.IsAdmin { + h.Elapsed1 = since.String() + } + co.PerfCounter.Push(since /*, false*/) } if c.RunPreRenderHook("pre_render_"+hookName, w, r, &h.CurrentUser, pi) { return nil diff --git a/routes/forum.go b/routes/forum.go index eab82a8a..cd842242 100644 --- a/routes/forum.go +++ b/routes/forum.go @@ -21,7 +21,7 @@ var forumStmts ForumStmts func init() { c.DbInits.Add(func(acc *qgen.Accumulator) error { forumStmts = ForumStmts{ - getTopics: acc.Select("topics").Columns("tid, title, content, createdBy, is_closed, sticky, createdAt, lastReplyAt, lastReplyBy, lastReplyID, parentID, views, postCount, likeCount").Where("parentID=?").Orderby("sticky DESC, lastReplyAt DESC, createdBy DESC").Limit("?,?").Prepare(), + getTopics: acc.Select("topics").Columns("tid, title, content, createdBy, is_closed, sticky, createdAt, lastReplyAt, lastReplyBy, lastReplyID, views, postCount, likeCount").Where("parentID=?").Orderby("sticky DESC, lastReplyAt DESC, createdBy DESC").Limit("?,?").Prepare(), } return acc.FirstError() }) @@ -69,11 +69,12 @@ func ViewForum(w http.ResponseWriter, r *http.Request, user c.User, header *c.He reqUserList := make(map[int]bool) for rows.Next() { t := c.TopicsRow{ID: 0} - err := rows.Scan(&t.ID, &t.Title, &t.Content, &t.CreatedBy, &t.IsClosed, &t.Sticky, &t.CreatedAt, &t.LastReplyAt, &t.LastReplyBy, &t.LastReplyID, &t.ParentID, &t.ViewCount, &t.PostCount, &t.LikeCount) + err := rows.Scan(&t.ID, &t.Title, &t.Content, &t.CreatedBy, &t.IsClosed, &t.Sticky, &t.CreatedAt, &t.LastReplyAt, &t.LastReplyBy, &t.LastReplyID, &t.ViewCount, &t.PostCount, &t.LikeCount) if err != nil { return c.InternalError(err, w, r) } + t.ParentID = fid t.Link = c.BuildTopicURL(c.NameToSlug(t.Title), t.ID) // TODO: Create a specialised function with a bit less overhead for getting the last page for a post count _, _, lastPage := c.PageOffset(t.PostCount, 1, c.Config.ItemsPerPage)