optimise away this string for non-admins

optimise away redundant parentID column on ViewForum
This commit is contained in:
Azareal 2020-03-01 09:15:48 +10:00
parent b1c9e0d11c
commit 5eaa8c8c89
2 changed files with 8 additions and 7 deletions

View File

@ -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

View File

@ -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)