@@ -2,6 +2,7 @@ package server
22
33import (
44 "github.com/labstack/echo"
5+ log "github.com/sirupsen/logrus"
56)
67
78type jsonResponseActivity struct {
@@ -16,7 +17,7 @@ type jsonResponse struct {
1617
1718func ActivityHandler (db Database ) echo.HandlerFunc {
1819 return func (c echo.Context ) error {
19- activity , next , err := db . Activity ( LocaleForRequest (c .Request ()), c .QueryParam ("next" ), 50 )
20+ activity , next , err := fetchActivity ( db , LocaleForRequest (c .Request ()), c .QueryParam ("next" ), c . QueryParam ( "nohelp" ) == "true" )
2021 if err != nil {
2122 return err
2223 }
@@ -41,3 +42,44 @@ func ActivityHandler(db Database) echo.HandlerFunc {
4142 return c .JSON (200 , response )
4243 }
4344}
45+
46+ const MinPageSize = 50
47+ const DbRequestSize = 50
48+ const MaxDbRequests = 10
49+
50+ func fetchActivity (db Database , locale * Locale , start string , nohelp bool ) ([]Activity , string , error ) {
51+ activity := []Activity {}
52+ next := start
53+ for i := 0 ; i < MaxDbRequests && len (activity ) < MinPageSize ; i ++ {
54+ as , n , err := db .Activity (locale , next , DbRequestSize )
55+ if err != nil {
56+ return nil , "" , err
57+ }
58+ next = n
59+ if len (as ) == 0 && n == "" {
60+ log .Debug ("end of activity db" )
61+ break
62+ }
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+ }
72+ activity = append (activity , a )
73+ }
74+ } else {
75+ activity = append (activity , as ... )
76+ }
77+ log .WithFields (log.Fields {
78+ "count" : len (as ),
79+ "buffered" : len (activity ),
80+ "skipped" : skipped ,
81+ "next" : next ,
82+ }).Debug ("processed activity batch" )
83+ }
84+ return activity , next , nil
85+ }
0 commit comments