Skip to content

Commit

Permalink
fix(activitylog): multiple minor bugfixes
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Jun 25, 2024
1 parent dcd319a commit 4f0e02f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/activitylog-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Various fixes for the activitylog service

First round of fixes to make the activitylog service more robust and reliable.

https://github.com/owncloud/ocis/pull/9467
1 change: 1 addition & 0 deletions services/activitylog/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var _registeredEvents = []events.Unmarshaller{
events.FileTouched{},
events.ContainerCreated{},
events.ItemTrashed{},
events.ItemPurged{},
events.ItemMoved{},
events.ShareCreated{},
events.ShareRemoved{},
Expand Down
7 changes: 6 additions & 1 deletion services/activitylog/pkg/service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/cs3org/reva/v2/pkg/utils"
"google.golang.org/grpc/metadata"

libregraph "github.com/owncloud/libre-graph-api-go"
"github.com/owncloud/ocis/v2/ocis-pkg/ast"
"github.com/owncloud/ocis/v2/ocis-pkg/kql"
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
Expand Down Expand Up @@ -83,7 +84,7 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
return
}

var resp GetActivitiesResponse
resp := GetActivitiesResponse{Activities: make([]libregraph.Activity, 0, len(evRes.GetEvents()))}
for _, e := range evRes.GetEvents() {
delete(toDelete, e.GetId())

Expand Down Expand Up @@ -269,6 +270,10 @@ func (s *ActivitylogService) getFilters(query string) (*provider.ResourceId, int
if err != nil {
return nil, limit, nil, nil, err
}
if rid.GetOpaqueId() == "" {
// space root requested - fix format
rid.OpaqueId = rid.GetSpaceId()
}
pref := func(a RawActivity) bool {
for _, f := range prefilters {
if !f(a) {
Expand Down
5 changes: 4 additions & 1 deletion services/activitylog/pkg/service/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func WithResource(ref *provider.Reference, addSpace bool) ActivityOption {
return func(ctx context.Context, gwc gateway.GatewayAPIClient, vars map[string]interface{}) error {
info, err := utils.GetResource(ctx, ref, gwc)
if err != nil {
vars["resource"] = Resource{
Name: filepath.Base(ref.GetPath()),
}
return err
}

Expand Down Expand Up @@ -209,7 +212,7 @@ func (s *ActivitylogService) GetVars(ctx context.Context, opts ...ActivityOption
vars := make(map[string]interface{})
for _, opt := range opts {
if err := opt(ctx, gwc, vars); err != nil {
return nil, err
s.log.Info().Err(err).Msg("error getting activity vars")
}
}

Expand Down
10 changes: 10 additions & 0 deletions services/activitylog/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func (a *ActivitylogService) Run() {
err = a.AddActivity(ev.Ref, e.ID, utils.TSToTime(ev.Timestamp))
case events.ItemTrashed:
err = a.AddActivityTrashed(ev.ID, ev.Ref, e.ID, utils.TSToTime(ev.Timestamp))
case events.ItemPurged:
err = a.RemoveResource(ev.ID)
case events.ItemMoved:
err = a.AddActivity(ev.Ref, e.ID, utils.TSToTime(ev.Timestamp))
case events.ShareCreated:
Expand Down Expand Up @@ -221,6 +223,14 @@ func (a *ActivitylogService) RemoveActivities(rid *provider.ResourceId, toDelete
})
}

// RemoveResource removes the resource from the store
func (a *ActivitylogService) RemoveResource(rid *provider.ResourceId) error {
a.lock.Lock()
defer a.lock.Unlock()

return a.store.Delete(storagespace.FormatResourceID(*rid))
}

func (a *ActivitylogService) activities(rid *provider.ResourceId) ([]RawActivity, error) {
resourceID := storagespace.FormatResourceID(*rid)

Expand Down

0 comments on commit 4f0e02f

Please sign in to comment.