order some filtering loops better to avoid repeated lookups

This commit is contained in:
Ted Unangst 2019-12-23 06:13:07 -05:00
parent 845fcf52f8
commit 5222332d91
2 changed files with 42 additions and 29 deletions

28
fun.go
View File

@ -104,24 +104,24 @@ func reverbolate(userid int64, honks []*Honk) {
h.Precis = string(p) h.Precis = string(p)
h.Noise = string(n) h.Noise = string(n)
} }
j := 0
if userid == -1 { for i := 0; i < len(h.Donks); i++ {
if h.Precis != "" { if !zap[h.Donks[i].XID] {
h.Open = "" h.Donks[j] = h.Donks[i]
} j++
} else {
unsee(userid, h)
if h.Open == "open" && h.Precis == "unspecified horror" {
h.Precis = ""
} }
} }
if len(h.Noise) > 6000 && h.Open == "open" { h.Donks = h.Donks[:j]
if h.Precis == "" {
h.Precis = "really freaking long"
}
h.Open = ""
} }
unsee(honks, userid)
for _, h := range honks {
local := false
if h.Whofore == 2 || h.Whofore == 3 {
local = true
}
zap := make(map[string]bool)
emuxifier := func(e string) string { emuxifier := func(e string) string {
for _, d := range h.Donks { for _, d := range h.Donks {
if d.Name == e { if d.Name == e {

23
hfcs.go
View File

@ -353,9 +353,12 @@ func skipMedia(xonk *Honk) bool {
return false return false
} }
func unsee(userid int64, h *Honk) { func unsee(honks []*Honk, userid int64) {
filts := getfilters(userid, filtCollapse) if userid != -1 {
for _, f := range filts { colfilts := getfilters(userid, filtCollapse)
rwfilts := getfilters(userid, filtRewrite)
for _, h := range honks {
for _, f := range colfilts {
if bad := matchfilterX(h, f); bad != "" { if bad := matchfilterX(h, f); bad != "" {
if h.Precis == "" { if h.Precis == "" {
h.Precis = bad h.Precis = bad
@ -364,12 +367,22 @@ func unsee(userid int64, h *Honk) {
break break
} }
} }
filts = getfilters(userid, filtRewrite) if h.Open == "open" && h.Precis == "unspecified horror" {
for _, f := range filts { h.Precis = ""
}
for _, f := range rwfilts {
if matchfilter(h, f) { if matchfilter(h, f) {
h.Noise = f.re_rewrite.ReplaceAllString(h.Noise, f.Replace) h.Noise = f.re_rewrite.ReplaceAllString(h.Noise, f.Replace)
} }
} }
if len(h.Noise) > 6000 && h.Open == "open" {
if h.Precis == "" {
h.Precis = "really freaking long"
}
h.Open = ""
}
}
}
} }
var untagged = cache.New(cache.Options{Filler: func(userid int64) (map[string]bool, bool) { var untagged = cache.New(cache.Options{Filler: func(userid int64) (map[string]bool, bool) {