cache default noavatar strings to avoid allocs
This commit is contained in:
parent
812471d15f
commit
e37c98eaa1
|
@ -95,11 +95,13 @@ type config struct {
|
|||
PostIPCutoff int
|
||||
PollIPCutoff int
|
||||
LogPruneCutoff int
|
||||
//SelfDeleteTruncCutoff int // Personal data is stripped from the mod action rows only leaving the TID and the action for later investigation.
|
||||
|
||||
DisableLastIP bool
|
||||
DisablePostIP bool
|
||||
DisablePollIP bool
|
||||
DisableRegLog bool
|
||||
//DisableSelfDeleteLog bool
|
||||
|
||||
DisableLiveTopicList bool
|
||||
DisableJSAntispam bool
|
||||
|
@ -168,7 +170,18 @@ func LoadConfig() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var noavatarCache200 []string
|
||||
var noavatarCache48 []string
|
||||
|
||||
func ProcessConfig() (err error) {
|
||||
if !Config.DisableDefaultNoavatar {
|
||||
noavatarCache200 = make([]string, 5)
|
||||
noavatarCache48 = make([]string, 5)
|
||||
for i := 0; i < 5; i++ {
|
||||
noavatarCache200[i] = "/s/n" + strconv.Itoa(i) + "-" + strconv.Itoa(200) + ".png?i=0"
|
||||
noavatarCache48[i] = "/s/n" + strconv.Itoa(i) + "-" + strconv.Itoa(48) + ".png?i=0"
|
||||
}
|
||||
}
|
||||
Config.Noavatar = strings.Replace(Config.Noavatar, "{site_url}", Site.URL, -1)
|
||||
guestAvatar = GuestAvatar{buildNoavatar(0, 200), buildNoavatar(0, 48)}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
//"log"
|
||||
|
||||
qgen "github.com/Azareal/Gosora/query_gen"
|
||||
|
@ -347,7 +348,7 @@ func (u *User) DeletePosts() error {
|
|||
tc := Topics.GetCache()
|
||||
umap := make(map[int]struct{})
|
||||
for rows.Next() {
|
||||
var tid, parentID, postCount,poll int
|
||||
var tid, parentID, postCount, poll int
|
||||
err := rows.Scan(&tid, &parentID, &postCount, &poll)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -384,7 +385,7 @@ func (u *User) DeletePosts() error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
err = Subscriptions.DeleteResource(tid,"topic")
|
||||
err = Subscriptions.DeleteResource(tid, "topic")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -427,7 +428,7 @@ func (u *User) DeletePosts() error {
|
|||
|
||||
for rows.Next() {
|
||||
var rid, uid int
|
||||
err := rows.Scan(&rid,&uid)
|
||||
err := rows.Scan(&rid, &uid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -437,7 +438,7 @@ func (u *User) DeletePosts() error {
|
|||
}
|
||||
// TODO: Optimise this
|
||||
// TODO: dismiss-event
|
||||
err = Activity.DeleteByParamsExtra("reply",uid,"user",strconv.Itoa(rid))
|
||||
err = Activity.DeleteByParamsExtra("reply", uid, "user", strconv.Itoa(rid))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -485,7 +486,7 @@ func (u *User) DeletePosts() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = Activity.DeleteByParamsExtra("reply",tid,"topic",strconv.Itoa(rid))
|
||||
err = Activity.DeleteByParamsExtra("reply", tid, "topic", strconv.Itoa(rid))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -720,6 +721,11 @@ func buildNoavatar(uid, width int) string {
|
|||
}
|
||||
}
|
||||
if !Config.DisableDefaultNoavatar && uid < 5 {
|
||||
if width == 200 {
|
||||
return noavatarCache200[uid]
|
||||
} else if width == 48 {
|
||||
return noavatarCache48[uid]
|
||||
}
|
||||
return "/s/n" + strconv.Itoa(uid) + "-" + strconv.Itoa(width) + ".png?i=0"
|
||||
}
|
||||
return strings.Replace(strings.Replace(Config.Noavatar, "{id}", strconv.Itoa(uid), 1), "{width}", strconv.Itoa(width), 1)
|
||||
|
@ -727,7 +733,7 @@ func buildNoavatar(uid, width int) string {
|
|||
|
||||
// ? Make this part of *User?
|
||||
// TODO: Write tests for this
|
||||
func BuildAvatar(uid int, avatar string) (normalAvatar string, microAvatar string) {
|
||||
func BuildAvatar(uid int, avatar string) (normalAvatar, microAvatar string) {
|
||||
if avatar == "" {
|
||||
if uid == 0 {
|
||||
return guestAvatar.Normal, guestAvatar.Micro
|
||||
|
|
Loading…
Reference in New Issue