Skip to content

Commit 77a52ba

Browse files
authored
Merge pull request #630 from iceljc/features/refine-cov-clean
add exclude agent ids
2 parents 75bba73 + 29af7cd commit 77a52ba

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface IConversationService
1313
Task<PagedItems<Conversation>> GetConversations(ConversationFilter filter);
1414
Task<Conversation> UpdateConversationTitle(string id, string title);
1515
Task<List<Conversation>> GetLastConversations();
16-
Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours);
16+
Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds);
1717
Task<bool> DeleteConversations(IEnumerable<string> ids);
1818

1919
/// <summary>

src/Infrastructure/BotSharp.Abstraction/Conversations/Settings/ConversationSetting.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public class ConversationSetting
1212
public bool EnableContentLog { get; set; }
1313
public bool EnableStateLog { get; set; }
1414
public bool EnableTranslationMemory { get; set; }
15-
public CleanConversationSetting CleanSetting { get; set; } = new CleanConversationSetting();
16-
public RateLimitSetting RateLimit { get; set; } = new RateLimitSetting();
15+
public CleanConversationSetting CleanSetting { get; set; } = new();
16+
public RateLimitSetting RateLimit { get; set; } = new();
1717
}
1818

1919
public class CleanConversationSetting
@@ -22,5 +22,5 @@ public class CleanConversationSetting
2222
public int BatchSize { get; set; }
2323
public int MessageLimit { get; set; }
2424
public int BufferHours { get; set; }
25-
25+
public IEnumerable<string> ExcludeAgentIds { get; set; } = new List<string>();
2626
}

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public interface IBotSharpRepository
6767
void UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint);
6868
ConversationBreakpoint? GetConversationBreakpoint(string conversationId);
6969
List<Conversation> GetLastConversations();
70-
List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours);
70+
List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds);
7171
IEnumerable<string> TruncateConversation(string conversationId, string messageId, bool cleanLog = false);
7272
#endregion
7373

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public async Task<List<Conversation>> GetLastConversations()
7070
return db.GetLastConversations();
7171
}
7272

73-
public async Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours)
73+
public async Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
7474
{
7575
var db = _services.GetRequiredService<IBotSharpRepository>();
76-
return db.GetIdleConversations(batchSize, messageLimit, bufferHours);
76+
return db.GetIdleConversations(batchSize, messageLimit, bufferHours, excludeAgentIds ?? new List<string>());
7777
}
7878

7979
public async Task<Conversation> NewConversation(Conversation sess)

src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public PagedItems<Conversation> GetConversations(ConversationFilter filter)
145145
public List<Conversation> GetLastConversations()
146146
=> throw new NotImplementedException();
147147

148-
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours)
148+
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
149149
=> throw new NotImplementedException();
150150

151151
public List<DialogElement> GetConversationDialogs(string conversationId)

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public List<Conversation> GetLastConversations()
378378
.ToList();
379379
}
380380

381-
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours)
381+
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
382382
{
383383
var ids = new List<string>();
384384
var batchLimit = 100;
@@ -423,7 +423,7 @@ public List<string> GetIdleConversations(int batchSize, int messageLimit, int bu
423423
continue;
424424
}
425425

426-
if (conv.UpdatedTime > utcNow.AddHours(-bufferHours))
426+
if (excludeAgentIds.Contains(conv.AgentId) || conv.UpdatedTime > utcNow.AddHours(-bufferHours))
427427
{
428428
continue;
429429
}

src/Infrastructure/BotSharp.OpenAPI/BackgroundServices/ConversationTimeoutService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private async Task CleanIdleConversationsAsync()
6262
if (cleanSetting == null || !cleanSetting.Enable) return;
6363

6464
var conversationService = scope.ServiceProvider.GetRequiredService<IConversationService>();
65-
var conversationIds = await conversationService.GetIdleConversations(cleanSetting.BatchSize, cleanSetting.MessageLimit, cleanSetting.BufferHours);
65+
var conversationIds = await conversationService.GetIdleConversations(cleanSetting.BatchSize, cleanSetting.MessageLimit, cleanSetting.BufferHours, cleanSetting.ExcludeAgentIds);
6666

6767
if (!conversationIds.IsNullOrEmpty())
6868
{

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public List<Conversation> GetLastConversations()
344344
}).ToList();
345345
}
346346

347-
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours)
347+
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
348348
{
349349
var page = 1;
350350
var batchLimit = 100;
@@ -370,7 +370,7 @@ public List<string> GetIdleConversations(int batchSize, int messageLimit, int bu
370370
{
371371
var skip = (page - 1) * batchSize;
372372
var candidates = _dc.Conversations.AsQueryable()
373-
.Where(x => x.DialogCount <= messageLimit && x.UpdatedTime <= utcNow.AddHours(-bufferHours))
373+
.Where(x => !excludeAgentIds.Contains(x.AgentId) && x.DialogCount <= messageLimit && x.UpdatedTime <= utcNow.AddHours(-bufferHours))
374374
.Skip(skip)
375375
.Take(batchSize)
376376
.Select(x => x.Id)

0 commit comments

Comments
 (0)