Skip to content

Commit

Permalink
feat(activitylog): add a mutex to the store
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Jun 24, 2024
1 parent a18ac33 commit 391e1f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion changelog/6.0.0_2024-06-19/activity-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ Enhancement: Activitylog Service

Adds a new service `activitylog` which stores events (activities) per resource. This data can be retrieved by clients to show item activities

https://github.com/owncloud/ocis/pull/9360
https://github.com/owncloud/ocis/pull/9327
5 changes: 5 additions & 0 deletions changelog/unreleased/activity-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Activitylog API

Adds an api to the `activitylog` service which allows retrieving data by clients to show item activities

https://github.com/owncloud/ocis/pull/9361
12 changes: 12 additions & 0 deletions services/activitylog/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"path/filepath"
"reflect"
"sync"
"time"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
Expand Down Expand Up @@ -40,6 +41,7 @@ type ActivitylogService struct {
mux *chi.Mux
evHistory ehsvc.EventHistoryService
valService settingssvc.ValueService
lock sync.RWMutex

registeredEvents map[string]events.Unmarshaller
}
Expand Down Expand Up @@ -73,6 +75,7 @@ func New(opts ...Option) (*ActivitylogService, error) {
mux: o.Mux,
evHistory: o.HistoryClient,
valService: o.ValueClient,
lock: sync.RWMutex{},
registeredEvents: make(map[string]events.Unmarshaller),
}

Expand Down Expand Up @@ -184,6 +187,9 @@ func (a *ActivitylogService) AddSpaceActivity(spaceID *provider.StorageSpaceId,

// Activities returns the activities for the given resource
func (a *ActivitylogService) Activities(rid *provider.ResourceId) ([]RawActivity, error) {
a.lock.RLock()
defer a.lock.RUnlock()

resourceID := storagespace.FormatResourceID(*rid)

records, err := a.store.Read(resourceID)
Expand All @@ -205,6 +211,9 @@ func (a *ActivitylogService) Activities(rid *provider.ResourceId) ([]RawActivity

// RemoveActivities removes the activities from the given resource
func (a *ActivitylogService) RemoveActivities(rid *provider.ResourceId, toDelete map[string]struct{}) error {
a.lock.Lock()
defer a.lock.Unlock()

curActivities, err := a.Activities(rid)
if err != nil {
return err
Expand Down Expand Up @@ -256,6 +265,9 @@ func (a *ActivitylogService) addActivity(initRef *provider.Reference, eventID st
}

func (a *ActivitylogService) storeActivity(resourceID string, eventID string, depth int, timestamp time.Time) error {
a.lock.Lock()
defer a.lock.Unlock()

records, err := a.store.Read(resourceID)
if err != nil && err != microstore.ErrNotFound {
return err
Expand Down

0 comments on commit 391e1f8

Please sign in to comment.