Skip to content

Commit 1a8fa0b

Browse files
committed
Batch remove message from Redis stream
1 parent 6b6467c commit 1a8fa0b

File tree

6 files changed

+5
-27
lines changed

6 files changed

+5
-27
lines changed

src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
<ItemGroup>
191191
<PackageReference Include="Aspects.Cache" Version="2.0.4" />
192192
<PackageReference Include="DistributedLock.Redis" Version="1.0.3" />
193-
<PackageReference Include="EntityFrameworkCore.BootKit" Version="8.7.1" />
193+
<PackageReference Include="EntityFrameworkCore.BootKit" Version="8.8.0" />
194194
<PackageReference Include="Fluid.Core" Version="2.11.1" />
195195
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
196196
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />

src/Infrastructure/BotSharp.Core/Infrastructures/Events/RedisPublisher.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,7 @@ public async Task RemoveAsync(string channel, int count = 10)
180180
var db = _redis.GetDatabase();
181181

182182
var entries = await db.StreamRangeAsync(channel, "-", "+", count: count, messageOrder: Order.Ascending);
183-
foreach (var entry in entries)
184-
{
185-
_logger.LogInformation($"Fetched message: {channel} {entry.Values[0].Value} ({entry.Id})");
186-
187-
try
188-
{
189-
await db.StreamDeleteAsync(channel, [entry.Id]);
190-
191-
_logger.LogWarning($"Deleted message: {channel} {entry.Values[0].Value} ({entry.Id})");
192-
}
193-
catch (Exception ex)
194-
{
195-
_logger.LogError($"Error processing message: {ex.Message}, event id: {channel} {entry.Id}\r\n{ex}");
196-
}
197-
}
183+
var deletedCount = await db.StreamDeleteAsync(channel, entries.Select(x => x.Id).ToArray());
184+
_logger.LogWarning($"Deleted {deletedCount} messages from Redis stream {channel}");
198185
}
199186
}

src/Infrastructure/BotSharp.Core/Infrastructures/Events/RedisSubscriber.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ await db.StreamAddAsync(errorChannel,
116116
}
117117
finally
118118
{
119-
await db.StreamDeleteAsync(channel, [entry.Id]);
119+
var deletedCount = await db.StreamDeleteAsync(channel, [entry.Id]);
120+
_logger.LogInformation($"Handled message {entry.Id}: {deletedCount == 1}");
120121
}
121122
}
122123

src/Plugins/BotSharp.Plugin.HttpHandler/BotSharp.Plugin.HttpHandler.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
</Content>
3434
</ItemGroup>
3535

36-
<ItemGroup>
37-
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
38-
</ItemGroup>
39-
4036
<ItemGroup>
4137
<ProjectReference Include="..\..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
4238
</ItemGroup>

src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDriverPlanningHook.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
using BotSharp.Abstraction.Agents.Enums;
21
using BotSharp.Abstraction.Messaging.Enums;
32
using BotSharp.Abstraction.Messaging.Models.RichContent.Template;
43
using BotSharp.Abstraction.Messaging.Models.RichContent;
54
using BotSharp.Abstraction.Messaging;
65
using BotSharp.Abstraction.Planning;
7-
using BotSharp.Abstraction.Routing;
86
using BotSharp.Core.Infrastructures;
9-
using System.Text.RegularExpressions;
10-
using BotSharp.Plugin.SqlDriver.Interfaces;
117

128
namespace BotSharp.Plugin.SqlDriver.Hooks;
139

src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using SQLitePCL;
2-
31
namespace BotSharp.Plugin.WebDriver.Functions;
42

53
public class OpenBrowserFn : IFunctionCallback

0 commit comments

Comments
 (0)