From 07f79e585a7dfd167b1bf63e2c33491ba02f4897 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Tue, 22 Oct 2024 11:06:01 +0200 Subject: [PATCH] fix(activitylog): Fix issues with many activities Signed-off-by: jkoberg --- .../unreleased/fix-activitylog-issues.md | 6 ++++++ services/activitylog/pkg/service/http.go | 21 ++++++++++--------- services/activitylog/pkg/service/service.go | 8 ++++++- 3 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 changelog/unreleased/fix-activitylog-issues.md diff --git a/changelog/unreleased/fix-activitylog-issues.md b/changelog/unreleased/fix-activitylog-issues.md new file mode 100644 index 00000000000..2ec4e961639 --- /dev/null +++ b/changelog/unreleased/fix-activitylog-issues.md @@ -0,0 +1,6 @@ +Bugfix: Fix Activitylog issues + +Fixes multiple activititylog issues. There was an error about `max payload exceeded` when there were too many activities on one folder. Listing would take very long even with a limit activated. All of these +issues are now fixed. + +https://github.com/owncloud/ocis/pull/10376 diff --git a/services/activitylog/pkg/service/http.go b/services/activitylog/pkg/service/http.go index c445f5221ff..5e7c77c6f50 100644 --- a/services/activitylog/pkg/service/http.go +++ b/services/activitylog/pkg/service/http.go @@ -103,10 +103,17 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h return } + evs := evRes.GetEvents() + sort(evs) + resp := GetActivitiesResponse{Activities: make([]libregraph.Activity, 0, len(evRes.GetEvents()))} - for _, e := range evRes.GetEvents() { + for _, e := range evs { delete(toDelete, e.GetId()) + if limit > 0 && limit <= len(resp.Activities) { + continue + } + if !activityAccepted(e) { continue } @@ -230,12 +237,6 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h }() } - sort(resp.Activities) - - if limit > 0 && limit < len(resp.Activities) { - resp.Activities = resp.Activities[:limit] - } - b, err := json.Marshal(resp) if err != nil { s.log.Error().Err(err).Msg("error marshalling activities") @@ -267,7 +268,7 @@ func (s *ActivitylogService) unwrapEvent(e *ehmsg.Event) interface{} { return einterface } -func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int, func(RawActivity) bool, func(*ehmsg.Event) bool, func([]libregraph.Activity), error) { +func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int, func(RawActivity) bool, func(*ehmsg.Event) bool, func([]*ehmsg.Event), error) { qast, err := kql.Builder{}.Build(query) if err != nil { return nil, 0, nil, nil, nil, err @@ -276,7 +277,7 @@ func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int prefilters := make([]func(RawActivity) bool, 0) postfilters := make([]func(*ehmsg.Event) bool, 0) - sortby := func(_ []libregraph.Activity) {} + sortby := func(_ []*ehmsg.Event) {} var ( itemID string @@ -313,7 +314,7 @@ func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int case "asc": // nothing to do - already ascending case "desc": - sortby = func(activities []libregraph.Activity) { + sortby = func(activities []*ehmsg.Event) { slices.Reverse(activities) } } diff --git a/services/activitylog/pkg/service/service.go b/services/activitylog/pkg/service/service.go index 302349c12b6..494e1e5f1bc 100644 --- a/services/activitylog/pkg/service/service.go +++ b/services/activitylog/pkg/service/service.go @@ -24,6 +24,9 @@ import ( "github.com/owncloud/ocis/v2/services/activitylog/pkg/config" ) +// Nats runs into max payload exceeded errors at around 7k activities. Let's keep a buffer. +var _maxActivities = 6000 + // RawActivity represents an activity as it is stored in the activitylog store type RawActivity struct { EventID string `json:"event_id"` @@ -311,7 +314,10 @@ func (a *ActivitylogService) storeActivity(resourceID string, eventID string, de } } - // TODO: max len check? + if l := len(activities); l >= _maxActivities { + activities = activities[l-_maxActivities+1:] + } + activities = append(activities, RawActivity{ EventID: eventID, Depth: depth,