Skip to content

Commit 3b5247b

Browse files
committed
revert GetIdleConversations
1 parent 4e1a2ea commit 3b5247b

File tree

1 file changed

+9
-39
lines changed

1 file changed

+9
-39
lines changed

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

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BotSharp.Abstraction.Conversations.Models;
22
using BotSharp.Abstraction.Repositories.Filters;
3+
using MongoDB.Driver.Linq;
34
using System.Text.Json;
45

56
namespace BotSharp.Plugin.MongoStorage.Repository;
@@ -560,45 +561,14 @@ public async Task<List<string>> GetIdleConversations(int batchSize, int messageL
560561
while (true)
561562
{
562563
var skip = (page - 1) * batchSize;
563-
var builder = Builders<ConversationDocument>.Filter;
564-
var filters = new List<FilterDefinition<ConversationDocument>>();
565-
566-
// Build the OR condition: (!excludeAgentIds.Contains(AgentId) && DialogCount <= messageLimit)
567-
// || (excludeAgentIds.Contains(AgentId) && DialogCount == 0)
568-
var orFilters = new List<FilterDefinition<ConversationDocument>>();
569-
570-
// First condition: !excludeAgentIds.Contains(AgentId) && DialogCount <= messageLimit
571-
if (excludeAgentIdsList.Any())
572-
{
573-
orFilters.Add(builder.And(
574-
builder.Nin(x => x.AgentId, excludeAgentIdsList),
575-
builder.Lte(x => x.DialogCount, messageLimit)
576-
));
577-
}
578-
else
579-
{
580-
// If excludeAgentIds is empty, all agents match the first condition
581-
orFilters.Add(builder.Lte(x => x.DialogCount, messageLimit));
582-
}
583-
584-
// Second condition: excludeAgentIds.Contains(AgentId) && DialogCount == 0
585-
if (excludeAgentIdsList.Any())
586-
{
587-
orFilters.Add(builder.And(
588-
builder.In(x => x.AgentId, excludeAgentIdsList),
589-
builder.Eq(x => x.DialogCount, 0)
590-
));
591-
}
592-
593-
filters.Add(builder.Or(orFilters));
594-
filters.Add(builder.Lte(x => x.UpdatedTime, utcNow.AddHours(-bufferHours)));
595-
596-
var filter = builder.And(filters);
597-
var candidates = await _dc.Conversations.Find(filter)
598-
.Skip(skip)
599-
.Limit(batchSize)
600-
.Project(x => x.Id)
601-
.ToListAsync();
564+
var candidates = await _dc.Conversations.AsQueryable()
565+
.Where(x => ((!excludeAgentIds.Contains(x.AgentId) && x.DialogCount <= messageLimit)
566+
|| (excludeAgentIds.Contains(x.AgentId) && x.DialogCount == 0))
567+
&& x.UpdatedTime <= utcNow.AddHours(-bufferHours))
568+
.Skip(skip)
569+
.Take(batchSize)
570+
.Select(x => x.Id)
571+
.ToListAsync();
602572

603573
if (candidates.IsNullOrEmpty())
604574
{

0 commit comments

Comments
 (0)