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.
This commit is contained in:
Azareal 2018-09-08 11:32:24 +10:00
parent 787108ceda
commit fd2a35cbcd
3 changed files with 16 additions and 6 deletions

View File

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

View File

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

View File

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