From aa303dc14da43260d9077da83f0cfdf45e1e438c Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 9 Mar 2020 17:11:58 +1000 Subject: [PATCH] use empty string instead of 0 for pruned ips eliminate a WriteRune call in BuildAlertSb --- common/alerts.go | 5 +++-- common/topic.go | 9 ++++----- routes/topic.go | 10 +++++----- tickloop.go | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/common/alerts.go b/common/alerts.go index ac9305ff..62481446 100644 --- a/common/alerts.go +++ b/common/alerts.go @@ -271,8 +271,7 @@ func BuildAlertSb(sb *strings.Builder, a *Alert, user User /* The current user * return errors.New(phrases.GetErrorPhrase("alerts_invalid_elementtype")) } - sb.WriteString(`{"msg":"`) - sb.WriteRune('.') + sb.WriteString(`{"msg":".`) sb.WriteString(a.ElementType) if own { sb.WriteString("_own_") @@ -299,6 +298,8 @@ func BuildAlertSb(sb *strings.Builder, a *Alert, user User /* The current user * return nil } +//var AlertsGrowHint3 = len(`{"msg":"._","sub":["",""],"path":"","avatar":"","id":}`) + 3 + 2 + 2 + 2 + 2 + 1 + func AddActivityAndNotifyAll(a Alert) error { id, err := Activity.Add(a) if err != nil { diff --git a/common/topic.go b/common/topic.go index 94a387ee..1b87617f 100644 --- a/common/topic.go +++ b/common/topic.go @@ -219,7 +219,7 @@ func init() { getRids: acc.Select("replies").Columns("rid").Where("tid=?").Orderby("rid ASC").Limit("?,?").Prepare(), getReplies: acc.SimpleLeftJoin("replies AS r", "users AS u", "r.rid, r.content, r.createdBy, r.createdAt, r.lastEdit, r.lastEditBy, u.avatar, u.name, u.group, u.level, r.ip, r.likeCount, r.attachCount, r.actionType", "r.createdBy = u.uid", "r.tid = ?", "r.rid ASC", "?,?"), addReplies: acc.Update(t).Set("postCount=postCount+?, lastReplyBy=?, lastReplyAt=UTC_TIMESTAMP()").Where("tid=?").Prepare(), - updateLastReply: acc.Update(t).Set("lastReplyID=?").Where("lastReplyID > ? AND tid = ?").Prepare(), + updateLastReply: acc.Update(t).Set("lastReplyID=?").Where("lastReplyID > ? AND tid=?").Prepare(), lock: acc.Update(t).Set("is_closed=1").Where("tid=?").Prepare(), unlock: acc.Update(t).Set("is_closed=0").Where("tid=?").Prepare(), moveTo: acc.Update(t).Set("parentID=?").Where("tid=?").Prepare(), @@ -670,12 +670,12 @@ func (t *TopicUser) Replies(offset, pFrag int, user *User) (rlist []*ReplyUser, } // TODO: This doesn't work properly so pick the first one instead? - if r.ID == pFrag { + /*if r.ID == pFrag { ogdesc = r.Content if len(ogdesc) > 200 { ogdesc = ogdesc[:197] + "..." } - } + }*/ if r.LikeCount > 0 && user.Liked > 0 { likedMap[r.ID] = len(rlist) @@ -722,8 +722,7 @@ func (t *TopicUser) Replies(offset, pFrag int, user *User) (rlist []*ReplyUser, return nil, "", err } } - err = rows.Err() - if err != nil { + if err = rows.Err(); err != nil { return nil, "", err } } diff --git a/routes/topic.go b/routes/topic.go index 5e161aaf..cf218e56 100644 --- a/routes/topic.go +++ b/routes/topic.go @@ -69,6 +69,11 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user c.User, header *c.He header.Title = topic.Title header.Path = c.BuildTopicURL(c.NameToSlug(topic.Title), topic.ID) + postGroup, err := c.Groups.Get(topic.Group) + if err != nil { + return c.InternalError(err, w, r) + } + topic.ContentLines = strings.Count(topic.Content, "\n") if len(topic.Content) > 200 { header.OGDesc = topic.Content[:197] + "..." @@ -76,11 +81,6 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user c.User, header *c.He header.OGDesc = topic.Content } - postGroup, err := c.Groups.Get(topic.Group) - if err != nil { - return c.InternalError(err, w, r) - } - var parseSettings *c.ParseSettings if !postGroup.Perms.AutoEmbed && (user.ParseSettings == nil || !user.ParseSettings.NoEmbed) { parseSettings = c.DefaultParseSettings.CopyPtr() diff --git a/tickloop.go b/tickloop.go index 527b7fb1..da5bd80d 100644 --- a/tickloop.go +++ b/tickloop.go @@ -189,7 +189,7 @@ func dailies() { if c.Config.DisablePostIP { f := func(tbl string) { - _, err := qgen.NewAcc().Update(tbl).Set("ip='0'").Where("ip!='0'").Exec() + _, err := qgen.NewAcc().Update(tbl).Set("ip=''").Where("ip!=''").Exec() if err != nil { c.LogError(err) } @@ -200,7 +200,7 @@ func dailies() { } else if c.Config.PostIPCutoff > -1 { // TODO: Use unixtime to remove this MySQLesque logic? f := func(tbl string) { - _, err := qgen.NewAcc().Update(tbl).Set("ip='0'").DateOlderThan("createdAt", c.Config.PostIPCutoff, "day").Where("ip!='0'").Exec() + _, err := qgen.NewAcc().Update(tbl).Set("ip=''").DateOlderThan("createdAt", c.Config.PostIPCutoff, "day").Where("ip!=''").Exec() if err != nil { c.LogError(err) } @@ -211,13 +211,13 @@ func dailies() { } if c.Config.DisablePollIP { - _, err := qgen.NewAcc().Update("polls_votes").Set("ip='0'").Where("ip!='0'").Exec() + _, err := qgen.NewAcc().Update("polls_votes").Set("ip=''").Where("ip!=''").Exec() if err != nil { c.LogError(err) } } else if c.Config.PollIPCutoff > -1 { // TODO: Use unixtime to remove this MySQLesque logic? - _, err := qgen.NewAcc().Update("polls_votes").Set("ip='0'").DateOlderThan("castAt", c.Config.PollIPCutoff, "day").Where("ip!='0'").Exec() + _, err := qgen.NewAcc().Update("polls_votes").Set("ip=''").DateOlderThan("castAt", c.Config.PollIPCutoff, "day").Where("ip!=''").Exec() if err != nil { c.LogError(err) } @@ -227,7 +227,7 @@ func dailies() { // TODO: lastActiveAt isn't currently set, so we can't rely on this to purge last_ips of users who haven't been on in a while if c.Config.DisableLastIP { - _, err := qgen.NewAcc().Update("users").Set("last_ip=0").Where("last_ip!=0").Exec() + _, err := qgen.NewAcc().Update("users").Set("last_ip=''").Where("last_ip!=''").Exec() if err != nil { c.LogError(err) } @@ -237,7 +237,7 @@ func dailies() { c.LogError(err) }*/ mon := time.Now().Month() - _, err := qgen.NewAcc().Update("users").Set("last_ip=0").Where("last_ip!='0' AND last_ip NOT LIKE '" + strconv.Itoa(int(mon)) + "-%'").Exec() + _, err := qgen.NewAcc().Update("users").Set("last_ip=''").Where("last_ip!='' AND last_ip NOT LIKE '" + strconv.Itoa(int(mon)) + "-%'").Exec() if err != nil { c.LogError(err) }