From fd2a35cbcd85049dbaff88d49e7216d7ba833891 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sat, 8 Sep 2018 11:32:24 +1000 Subject: [PATCH] Topic views should roughly update once every fifteen minutes in the UI now. Fixed a bug where int64s wouldn't work properly in transpiled templates. Changed the type of ViewCount in the topic structs to int64. --- common/counters/topics_views.go | 12 +++++++++++- common/templates/templates.go | 2 +- common/topic.go | 8 ++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/common/counters/topics_views.go b/common/counters/topics_views.go index 8de55e79..e5e81d16 100644 --- a/common/counters/topics_views.go +++ b/common/counters/topics_views.go @@ -3,6 +3,7 @@ package counters import ( "database/sql" "sync" + "sync/atomic" ".." "../../query_gen/lib" @@ -82,7 +83,16 @@ func (counter *DefaultTopicViewCounter) insertChunk(count int, topicID int) erro } common.DebugLogf("Inserting %d views into topic %d", count, topicID) _, err := counter.update.Exec(count, topicID) - return err + if err != nil { + return err + } + // TODO: Add a way to disable this for extra speed ;) + topic, err := common.Topics.Get(topicID) + if err != nil { + return err + } + atomic.AddInt64(&topic.ViewCount, int64(count)) + return nil } func (counter *DefaultTopicViewCounter) Bump(topicID int) { diff --git a/common/templates/templates.go b/common/templates/templates.go index 362a05f2..f0964d62 100644 --- a/common/templates/templates.go +++ b/common/templates/templates.go @@ -913,7 +913,7 @@ func (c *CTemplateSet) compileVarsub(varname string, val reflect.Value, assLines out = "w.Write([]byte(" + varname + "))\n" case reflect.Int64: c.importMap["strconv"] = "strconv" - out = "w.Write([]byte(strconv.FormatInt(" + varname + ", 10)))" + out = "w.Write([]byte(strconv.FormatInt(" + varname + ", 10)))\n" default: if !val.IsValid() { panic(assLines + varname + "^\n" + "Invalid value. Maybe, it doesn't exist?") diff --git a/common/topic.go b/common/topic.go index d4b74787..5b634d7a 100644 --- a/common/topic.go +++ b/common/topic.go @@ -37,7 +37,7 @@ type Topic struct { ParentID int Status string // Deprecated. Marked for removal. IPAddress string - ViewCount int + ViewCount int64 PostCount int LikeCount int ClassName string // CSS Class Name @@ -61,7 +61,7 @@ type TopicUser struct { ParentID int Status string // Deprecated. Marked for removal. IPAddress string - ViewCount int + ViewCount int64 PostCount int LikeCount int ClassName string @@ -99,7 +99,7 @@ type TopicsRow struct { ParentID int Status string // Deprecated. Marked for removal. -Is there anything we could use it for? IPAddress string - ViewCount int + ViewCount int64 PostCount int LikeCount int ClassName string @@ -126,7 +126,7 @@ type WsTopicsRow struct { RelativeLastReplyAt string LastReplyBy int ParentID int - ViewCount int + ViewCount int64 PostCount int LikeCount int ClassName string