Skip to content

Commit be4a9a5

Browse files
authored
Merge pull request #229 from iceljc/bugfix/delete-conversation-logs
fix typo and delete logs
2 parents 9d44878 + e1c32a5 commit be4a9a5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExectionLogCollection.cs renamed to src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExecutionLogCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace BotSharp.Plugin.MongoStorage.Collections;
22

3-
public class ExectionLogCollection : MongoBase
3+
public class ExecutionLogCollection : MongoBase
44
{
55
public string ConversationId { get; set; }
66
public List<string> Logs { get; set; }

src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public IMongoCollection<ConversationCollection> Conversations
3737
public IMongoCollection<ConversationDialogCollection> ConversationDialogs
3838
=> Database.GetCollection<ConversationDialogCollection>($"{_collectionPrefix}_ConversationDialogs");
3939

40-
public IMongoCollection<ExectionLogCollection> ExectionLogs
41-
=> Database.GetCollection<ExectionLogCollection>($"{_collectionPrefix}_ExectionLogs");
40+
public IMongoCollection<ExecutionLogCollection> ExectionLogs
41+
=> Database.GetCollection<ExecutionLogCollection>($"{_collectionPrefix}_ExecutionLogs");
4242

4343
public IMongoCollection<UserCollection> Users
4444
=> Database.GetCollection<UserCollection>($"{_collectionPrefix}_Users");

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,14 @@ public void CreateNewConversation(Conversation conversation)
605605
public bool DeleteConversation(string conversationId)
606606
{
607607
if (string.IsNullOrEmpty(conversationId)) return false;
608+
608609
var filterConv = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
609610
var filterDialog = Builders<ConversationDialogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
611+
var filterExeLog = Builders<ExecutionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
612+
var filterPromptLog = Builders<LlmCompletionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
610613

614+
var exeLogDeleted = _dc.ExectionLogs.DeleteMany(filterExeLog);
615+
var promptLogDeleted = _dc.LlmCompletionLogs.DeleteMany(filterPromptLog);
611616
var dialogDeleted = _dc.ConversationDialogs.DeleteMany(filterDialog);
612617
var convDeleted = _dc.Conversations.DeleteMany(filterConv);
613618
return convDeleted.DeletedCount > 0 || dialogDeleted.DeletedCount > 0;
@@ -843,8 +848,8 @@ public void AddExecutionLogs(string conversationId, List<string> logs)
843848
{
844849
if (string.IsNullOrEmpty(conversationId) || logs.IsNullOrEmpty()) return;
845850

846-
var filter = Builders<ExectionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
847-
var update = Builders<ExectionLogCollection>.Update
851+
var filter = Builders<ExecutionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
852+
var update = Builders<ExecutionLogCollection>.Update
848853
.SetOnInsert(x => x.Id, Guid.NewGuid().ToString())
849854
.PushEach(x => x.Logs, logs);
850855

@@ -856,7 +861,7 @@ public List<string> GetExecutionLogs(string conversationId)
856861
var logs = new List<string>();
857862
if (string.IsNullOrEmpty(conversationId)) return logs;
858863

859-
var filter = Builders<ExectionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
864+
var filter = Builders<ExecutionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
860865
var logCollection = _dc.ExectionLogs.Find(filter).FirstOrDefault();
861866

862867
logs = logCollection?.Logs ?? new List<string>();

0 commit comments

Comments
 (0)