From 646c1f25454c6446d5cb16612c9d314d4c5076da Mon Sep 17 00:00:00 2001 From: Azareal Date: Tue, 11 Sep 2018 22:21:15 +1000 Subject: [PATCH] Don't prematurely load topics just to increment their cached view counts. --- common/counters/topics_views.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/counters/topics_views.go b/common/counters/topics_views.go index e5e81d16..f473fdfb 100644 --- a/common/counters/topics_views.go +++ b/common/counters/topics_views.go @@ -81,17 +81,23 @@ func (counter *DefaultTopicViewCounter) insertChunk(count int, topicID int) erro if count == 0 { return nil } + common.DebugLogf("Inserting %d views into topic %d", count, topicID) _, err := counter.update.Exec(count, topicID) 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 + tcache := common.Topics.GetCache() + if tcache != nil { + topic, err := tcache.Get(topicID) + if err != nil { + return err + } + atomic.AddInt64(&topic.ViewCount, int64(count)) } - atomic.AddInt64(&topic.ViewCount, int64(count)) + return nil }