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"))
}
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 {

View File

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

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.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()

View File

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