about summary refs log tree commit diff
path: root/MatrixContentFilter/Services/BotModeSanityCheckService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixContentFilter/Services/BotModeSanityCheckService.cs')
-rw-r--r--MatrixContentFilter/Services/BotModeSanityCheckService.cs14
1 files changed, 7 insertions, 7 deletions
diff --git a/MatrixContentFilter/Services/BotModeSanityCheckService.cs b/MatrixContentFilter/Services/BotModeSanityCheckService.cs

index 55fe9e8..0a99ca1 100644 --- a/MatrixContentFilter/Services/BotModeSanityCheckService.cs +++ b/MatrixContentFilter/Services/BotModeSanityCheckService.cs
@@ -1,13 +1,8 @@ -using System.Diagnostics; -using ArcaneLibs; using ArcaneLibs.Extensions; -using LibMatrix; using LibMatrix.Filters; using LibMatrix.Helpers; using LibMatrix.Homeservers; -using LibMatrix.Responses; using MatrixContentFilter.Abstractions; -using MatrixContentFilter.Handlers.Filters; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -18,19 +13,22 @@ public class BotModeSanityCheckService( AuthenticatedHomeserverGeneric hs, ConfigurationService filterConfigService, IEnumerable<IContentFilter> filters, - AsyncMessageQueue msgQueue + AsyncMessageQueue msgQueue, + MatrixContentFilterConfiguration cfg ) : BackgroundService { /// <summary>Triggered when the application host is ready to start the service.</summary> /// <param name="cancellationToken">Indicates that the start process has been aborted.</param> protected override async Task ExecuteAsync(CancellationToken cancellationToken) { + var semaphore = new SemaphoreSlim(cfg.SanityCheck.MaxConcurrency); while (!cancellationToken.IsCancellationRequested) { - await Task.Delay(10000, cancellationToken); + await Task.Delay(cfg.SanityCheck.Interval, cancellationToken); var rooms = await hs.GetJoinedRooms(); rooms.RemoveAll(x => x.RoomId == filterConfigService.LogRoom.RoomId); rooms.RemoveAll(x => x.RoomId == filterConfigService.ControlRoom.RoomId); var timelineFilter = new SyncFilter.RoomFilter.StateFilter(notTypes: ["m.room.redaction"], limit: 5000); var timelines = rooms.Select(async x => { + await semaphore.WaitAsync(cancellationToken); var room = hs.GetRoom(x.RoomId); // var sync = await room.GetMessagesAsync(null, 1500, filter: timelineFilter.ToJson(ignoreNull: true, indent: false).UrlEncode()); var iter = room.GetManyMessagesAsync(null, 5000, filter: timelineFilter.ToJson(ignoreNull: true, indent: false).UrlEncode(), chunkSize: 250); @@ -49,6 +47,8 @@ public class BotModeSanityCheckService( await tasks; } + + semaphore.Release(); }).ToList(); await Task.WhenAll(timelines); }