Skip to content

Commit

Permalink
Merge pull request #10507 from owncloud/fix-autoaccept-concurrency
Browse files Browse the repository at this point in the history
fix autoaccept concurrency
  • Loading branch information
butonic authored Nov 7, 2024
2 parents be5b216 + 3c6c253 commit d5c5e80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog/unreleased/concurrent-autoaccept.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Enhancement: Concurrent autoaccept for shares

Shares for groups are now concurrently accepted. Tha default of 25 goroutinges can be changed with the new `FRONTEND_MAX_CONCURRENCY` environment variable.

https://github.com/owncloud/ocis/pull/10505
https://github.com/owncloud/ocis/pull/10476
35 changes: 23 additions & 12 deletions services/frontend/pkg/command/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,31 @@ func ListenForEvents(ctx context.Context, cfg *config.Config, l log.Logger) erro

valueService := settingssvc.NewValueService("com.owncloud.api.settings", grpcClient)

for {
select {
case e := <-evChannel:
switch ev := e.Event.(type) {
default:
l.Error().Interface("event", e).Msg("unhandled event")
case events.ShareCreated:
AutoAcceptShares(ev, cfg.AutoAcceptShares, l, gatewaySelector, valueService, cfg.ServiceAccount, cfg.MaxConcurrency)
wg := sync.WaitGroup{}
for i := 0; i < cfg.MaxConcurrency; i++ {
wg.Add(1)
go func(ch <-chan events.Event) {
defer wg.Done()
for {
select {
case e := <-ch:
switch ev := e.Event.(type) {
default:
l.Error().Interface("event", e).Msg("unhandled event")
case events.ShareCreated:
AutoAcceptShares(ev, cfg.AutoAcceptShares, l, gatewaySelector, valueService, cfg.ServiceAccount, cfg.MaxConcurrency)
}
case <-ctx.Done():
l.Info().Msg("context cancelled")
return
}
}
case <-ctx.Done():
l.Info().Msg("context cancelled")
return nil
}
}(evChannel)
}
// Wait for all goroutines to finish
wg.Wait()

return nil
}

// AutoAcceptShares automatically accepts shares if configured by the admin or user
Expand Down

0 comments on commit d5c5e80

Please sign in to comment.