diff --git a/backend/src/Squidex.Domain.Apps.Entities/History/NotifoService.cs b/backend/src/Squidex.Domain.Apps.Entities/History/NotifoService.cs index 23bf294c5..55652f5b6 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/History/NotifoService.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/History/NotifoService.cs @@ -131,11 +131,11 @@ namespace Squidex.Domain.Apps.Entities.History .Where(x => IsComment(x.AppEvent.Payload) || x.HistoryEvent != null) .ToList(); - if (publishedEvents.Any()) + foreach (var batch in publishedEvents.Batch(50)) { var requests = new List(); - foreach (var @event in publishedEvents) + foreach (var @event in batch) { var payload = @event.AppEvent.Payload; diff --git a/backend/src/Squidex.Infrastructure/CollectionExtensions.cs b/backend/src/Squidex.Infrastructure/CollectionExtensions.cs index ebf208b22..5ebe19519 100644 --- a/backend/src/Squidex.Infrastructure/CollectionExtensions.cs +++ b/backend/src/Squidex.Infrastructure/CollectionExtensions.cs @@ -16,6 +16,38 @@ namespace Squidex.Infrastructure { public static class CollectionExtensions { + public static IEnumerable> Batch(this IEnumerable source, int size) + { + TSource[]? bucket = null; + + var bucketIndex = 0; + + foreach (var item in source) + { + if (bucket == null) + { + bucket = new TSource[size]; + } + + bucket[bucketIndex++] = item; + + if (bucketIndex != size) + { + continue; + } + + yield return bucket; + + bucket = null; + bucketIndex = 0; + } + + if (bucket != null && bucketIndex > 0) + { + yield return bucket.Take(bucketIndex); + } + } + public static async Task> ToListAsync(this IAsyncEnumerable source) { var result = new List();