@@ -2,7 +2,6 @@ package server
22
33import (
44 "github.com/labstack/echo"
5- log "github.com/sirupsen/logrus"
65)
76
87type jsonResponseActivity struct {
@@ -17,7 +16,21 @@ type jsonResponse struct {
1716
1817func ActivityHandler (db Database ) echo.HandlerFunc {
1918 return func (c echo.Context ) error {
20- activity , next , err := fetchActivity (db , LocaleForRequest (c .Request ()), c .QueryParam ("next" ), c .QueryParam ("nohelp" ) == "true" )
19+ locale := LocaleForRequest (c .Request ())
20+ filter := func (a Activity ) bool {
21+ return true
22+ }
23+ if c .QueryParam ("nohelp" ) == "true" {
24+ filter = func (a Activity ) bool {
25+ if fp , ok := a .(* ForumPost ); ok {
26+ if fp .ForumId == locale .HelpForumId {
27+ return false
28+ }
29+ }
30+ return true
31+ }
32+ }
33+ activity , next , err := db .Activity (locale , c .QueryParam ("next" ), 50 , filter )
2134 if err != nil {
2235 return err
2336 }
@@ -42,51 +55,3 @@ func ActivityHandler(db Database) echo.HandlerFunc {
4255 return c .JSON (200 , response )
4356 }
4457}
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- 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- }
66- for i := 0 ; i < MaxDbRequests && len (activity ) < MinPageSize ; i ++ {
67- as , n , err := db .Activity (locale , next , DbRequestSize )
68- if err != nil {
69- return nil , "" , err
70- }
71- next = n
72- if len (as ) == 0 && n == "" {
73- log .Debug ("end of activity db" )
74- break
75- }
76- filtered := 0
77- for _ , a := range as {
78- if pred (a ) {
79- activity = append (activity , a )
80- } else {
81- filtered ++
82- }
83- }
84- log .WithFields (log.Fields {
85- "count" : len (as ),
86- "buffered" : len (activity ),
87- "filtered" : filtered ,
88- "next" : next ,
89- }).Debug ("processed activity batch" )
90- }
91- return activity , next , nil
92- }
0 commit comments