use empty string instead of 0 for pruned ips

eliminate a WriteRune call in BuildAlertSb
This commit is contained in:
Azareal 2020-03-09 17:11:58 +10:00
parent 28f210371e
commit aa303dc14d
4 changed files with 18 additions and 18 deletions

View File

@ -271,8 +271,7 @@ func BuildAlertSb(sb *strings.Builder, a *Alert, user User /* The current user *
return errors.New(phrases.GetErrorPhrase("alerts_invalid_elementtype")) return errors.New(phrases.GetErrorPhrase("alerts_invalid_elementtype"))
} }
sb.WriteString(`{"msg":"`) sb.WriteString(`{"msg":".`)
sb.WriteRune('.')
sb.WriteString(a.ElementType) sb.WriteString(a.ElementType)
if own { if own {
sb.WriteString("_own_") sb.WriteString("_own_")
@ -299,6 +298,8 @@ func BuildAlertSb(sb *strings.Builder, a *Alert, user User /* The current user *
return nil return nil
} }
//var AlertsGrowHint3 = len(`{"msg":"._","sub":["",""],"path":"","avatar":"","id":}`) + 3 + 2 + 2 + 2 + 2 + 1
func AddActivityAndNotifyAll(a Alert) error { func AddActivityAndNotifyAll(a Alert) error {
id, err := Activity.Add(a) id, err := Activity.Add(a)
if err != nil { if err != nil {

View File

@ -219,7 +219,7 @@ func init() {
getRids: acc.Select("replies").Columns("rid").Where("tid=?").Orderby("rid ASC").Limit("?,?").Prepare(), 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", "?,?"), 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(), 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(), lock: acc.Update(t).Set("is_closed=1").Where("tid=?").Prepare(),
unlock: acc.Update(t).Set("is_closed=0").Where("tid=?").Prepare(), unlock: acc.Update(t).Set("is_closed=0").Where("tid=?").Prepare(),
moveTo: acc.Update(t).Set("parentID=?").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? // TODO: This doesn't work properly so pick the first one instead?
if r.ID == pFrag { /*if r.ID == pFrag {
ogdesc = r.Content ogdesc = r.Content
if len(ogdesc) > 200 { if len(ogdesc) > 200 {
ogdesc = ogdesc[:197] + "..." ogdesc = ogdesc[:197] + "..."
} }
} }*/
if r.LikeCount > 0 && user.Liked > 0 { if r.LikeCount > 0 && user.Liked > 0 {
likedMap[r.ID] = len(rlist) likedMap[r.ID] = len(rlist)
@ -722,8 +722,7 @@ func (t *TopicUser) Replies(offset, pFrag int, user *User) (rlist []*ReplyUser,
return nil, "", err return nil, "", err
} }
} }
err = rows.Err() if err = rows.Err(); err != nil {
if err != nil {
return nil, "", err return nil, "", err
} }
} }

View File

@ -69,6 +69,11 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user c.User, header *c.He
header.Title = topic.Title header.Title = topic.Title
header.Path = c.BuildTopicURL(c.NameToSlug(topic.Title), topic.ID) 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") topic.ContentLines = strings.Count(topic.Content, "\n")
if len(topic.Content) > 200 { if len(topic.Content) > 200 {
header.OGDesc = topic.Content[:197] + "..." 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 header.OGDesc = topic.Content
} }
postGroup, err := c.Groups.Get(topic.Group)
if err != nil {
return c.InternalError(err, w, r)
}
var parseSettings *c.ParseSettings var parseSettings *c.ParseSettings
if !postGroup.Perms.AutoEmbed && (user.ParseSettings == nil || !user.ParseSettings.NoEmbed) { if !postGroup.Perms.AutoEmbed && (user.ParseSettings == nil || !user.ParseSettings.NoEmbed) {
parseSettings = c.DefaultParseSettings.CopyPtr() parseSettings = c.DefaultParseSettings.CopyPtr()

View File

@ -189,7 +189,7 @@ func dailies() {
if c.Config.DisablePostIP { if c.Config.DisablePostIP {
f := func(tbl string) { 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 { if err != nil {
c.LogError(err) c.LogError(err)
} }
@ -200,7 +200,7 @@ func dailies() {
} else if c.Config.PostIPCutoff > -1 { } else if c.Config.PostIPCutoff > -1 {
// TODO: Use unixtime to remove this MySQLesque logic? // TODO: Use unixtime to remove this MySQLesque logic?
f := func(tbl string) { 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 { if err != nil {
c.LogError(err) c.LogError(err)
} }
@ -211,13 +211,13 @@ func dailies() {
} }
if c.Config.DisablePollIP { 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 { if err != nil {
c.LogError(err) c.LogError(err)
} }
} else if c.Config.PollIPCutoff > -1 { } else if c.Config.PollIPCutoff > -1 {
// TODO: Use unixtime to remove this MySQLesque logic? // 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 { if err != nil {
c.LogError(err) 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 // 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 { 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 { if err != nil {
c.LogError(err) c.LogError(err)
} }
@ -237,7 +237,7 @@ func dailies() {
c.LogError(err) c.LogError(err)
}*/ }*/
mon := time.Now().Month() 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 { if err != nil {
c.LogError(err) c.LogError(err)
} }