Don't prematurely load topics just to increment their cached view counts.

This commit is contained in:
Azareal 2018-09-11 22:21:15 +10:00
parent 01040b200d
commit 646c1f2545

View File

@ -81,17 +81,23 @@ func (counter *DefaultTopicViewCounter) insertChunk(count int, topicID int) erro
if count == 0 { if count == 0 {
return nil return nil
} }
common.DebugLogf("Inserting %d views into topic %d", count, topicID) common.DebugLogf("Inserting %d views into topic %d", count, topicID)
_, err := counter.update.Exec(count, topicID) _, err := counter.update.Exec(count, topicID)
if err != nil { if err != nil {
return err return err
} }
// TODO: Add a way to disable this for extra speed ;) // TODO: Add a way to disable this for extra speed ;)
topic, err := common.Topics.Get(topicID) tcache := common.Topics.GetCache()
if err != nil { if tcache != nil {
return err topic, err := tcache.Get(topicID)
if err != nil {
return err
}
atomic.AddInt64(&topic.ViewCount, int64(count))
} }
atomic.AddInt64(&topic.ViewCount, int64(count))
return nil return nil
} }