From 9b2bae31c9ffd24219bb1f98eedd975fcfaeb811 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Wed, 25 Sep 2024 13:45:35 +0200 Subject: [PATCH] fix(activitylog): fix limit parameter Signed-off-by: jkoberg --- changelog/unreleased/fix-activity-limit.md | 5 +++++ services/activitylog/pkg/service/http.go | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changelog/unreleased/fix-activity-limit.md diff --git a/changelog/unreleased/fix-activity-limit.md b/changelog/unreleased/fix-activity-limit.md new file mode 100644 index 00000000000..06e42044c51 --- /dev/null +++ b/changelog/unreleased/fix-activity-limit.md @@ -0,0 +1,5 @@ +Bugfix: Fix activity limit + +When requesting a limit on activities, ocis would limit first, then filter and sort. Now it filters and sorts first, then limits. + +https://github.com/owncloud/ocis/pull/10165 diff --git a/services/activitylog/pkg/service/http.go b/services/activitylog/pkg/service/http.go index d888b9052a6..d3b5455b866 100644 --- a/services/activitylog/pkg/service/http.go +++ b/services/activitylog/pkg/service/http.go @@ -107,10 +107,6 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h for _, e := range evRes.GetEvents() { delete(toDelete, e.GetId()) - if limit != 0 && len(resp.Activities) >= limit { - continue - } - if !activityAccepted(e) { continue } @@ -221,6 +217,10 @@ 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")