fix(activitylog): Fix issues with many activities

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2024-10-22 11:06:01 +02:00
parent d5aea1e64a
commit 07f79e585a
3 changed files with 24 additions and 11 deletions

View File

@@ -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

View File

@@ -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)
}
}

View File

@@ -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,