Skip to content

Commit 7321f70

Browse files
committed
make fetchActivity more readable
1 parent a11db20 commit 7321f70

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

server/activity_handler.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ const MaxDbRequests = 10
5050
func fetchActivity(db Database, locale *Locale, start string, nohelp bool) ([]Activity, string, error) {
5151
activity := []Activity{}
5252
next := start
53+
pred := func(a Activity) bool {
54+
return true
55+
}
56+
if nohelp {
57+
pred = func(a Activity) bool {
58+
if fp, ok := a.(*ForumPost); ok {
59+
if fp.ForumId == locale.HelpForumId {
60+
return false
61+
}
62+
}
63+
return true
64+
}
65+
}
5366
for i := 0; i < MaxDbRequests && len(activity) < MinPageSize; i++ {
5467
as, n, err := db.Activity(locale, next, DbRequestSize)
5568
if err != nil {
@@ -60,24 +73,18 @@ func fetchActivity(db Database, locale *Locale, start string, nohelp bool) ([]Ac
6073
log.Debug("end of activity db")
6174
break
6275
}
63-
skipped := 0
64-
if nohelp {
65-
for _, a := range as {
66-
if fp, ok := a.(*ForumPost); ok {
67-
if fp.ForumId == locale.HelpForumId {
68-
skipped++
69-
continue
70-
}
71-
}
76+
filtered := 0
77+
for _, a := range as {
78+
if pred(a) {
7279
activity = append(activity, a)
80+
} else {
81+
filtered++
7382
}
74-
} else {
75-
activity = append(activity, as...)
7683
}
7784
log.WithFields(log.Fields{
7885
"count": len(as),
7986
"buffered": len(activity),
80-
"skipped": skipped,
87+
"filtered": filtered,
8188
"next": next,
8289
}).Debug("processed activity batch")
8390
}

0 commit comments

Comments
 (0)