Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix autoaccept concurrency #10507

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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