Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make fetchActivity more readable
  • Loading branch information
abr-egn committed Dec 26, 2024
commit 7321f70b3a47e27b196d958fce2f032f42ae300f
31 changes: 19 additions & 12 deletions server/activity_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ const MaxDbRequests = 10
func fetchActivity(db Database, locale *Locale, start string, nohelp bool) ([]Activity, string, error) {
activity := []Activity{}
next := start
pred := func(a Activity) bool {
return true
}
if nohelp {
pred = func(a Activity) bool {
if fp, ok := a.(*ForumPost); ok {
if fp.ForumId == locale.HelpForumId {
return false
}
}
return true
}
}
for i := 0; i < MaxDbRequests && len(activity) < MinPageSize; i++ {
as, n, err := db.Activity(locale, next, DbRequestSize)
if err != nil {
Expand All @@ -60,24 +73,18 @@ func fetchActivity(db Database, locale *Locale, start string, nohelp bool) ([]Ac
log.Debug("end of activity db")
break
}
skipped := 0
if nohelp {
for _, a := range as {
if fp, ok := a.(*ForumPost); ok {
if fp.ForumId == locale.HelpForumId {
skipped++
continue
}
}
filtered := 0
for _, a := range as {
if pred(a) {
activity = append(activity, a)
} else {
filtered++
}
} else {
activity = append(activity, as...)
}
log.WithFields(log.Fields{
"count": len(as),
"buffered": len(activity),
"skipped": skipped,
"filtered": filtered,
"next": next,
}).Debug("processed activity batch")
}
Expand Down