From 3b68ef75b66f1afb67886a888beaa2468698a493 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Mon, 13 May 2024 11:32:11 -0500 Subject: [PATCH 1/4] fix truncate breakpoint --- .../FileRepository/FileRepository.Conversation.cs | 7 +++---- .../Repository/MongoRepository.Conversation.cs | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs index 38f47f9f..5ccd3777 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs @@ -481,7 +481,7 @@ namespace BotSharp.Core.Repository // Handle truncated breakpoints var breakpointDir = Path.Combine(convDir, BREAKPOINT_FILE); var breakpoints = CollectConversationBreakpoints(breakpointDir); - isSaved = HandleTruncatedBreakpoints(breakpointDir, breakpoints, messageId); + isSaved = HandleTruncatedBreakpoints(breakpointDir, breakpoints, refTime); // Remove logs if (cleanLog) @@ -585,10 +585,9 @@ namespace BotSharp.Core.Repository return isSaved; } - private bool HandleTruncatedBreakpoints(string breakpointDir, List breakpoints, string refMessageId) + private bool HandleTruncatedBreakpoints(string breakpointDir, List breakpoints, DateTime refTime) { - var targetIdx = breakpoints.FindIndex(x => x.MessageId == refMessageId); - var truncatedBreakpoints = breakpoints?.Where((x, idx) => idx < targetIdx)? + var truncatedBreakpoints = breakpoints?.Where(x => x.CreatedTime < refTime)? .ToList() ?? new List(); var isSaved = SaveTruncatedBreakpoints(breakpointDir, truncatedBreakpoints); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index cfd3199d..aefd0db5 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -452,8 +452,7 @@ public partial class MongoRepository if (!foundStates.Breakpoints.IsNullOrEmpty()) { var breakpoints = foundStates.Breakpoints ?? new List(); - var targetIdx = breakpoints.FindIndex(x => x.MessageId == messageId); - var truncatedBreakpoints = breakpoints.Where((x, idx) => idx < targetIdx).ToList(); + var truncatedBreakpoints = breakpoints.Where(x => x.CreatedTime < refTime).ToList(); foundStates.Breakpoints = truncatedBreakpoints; } From 8c2b77b45da5255af7e0f7393f8b33c18a296ebe Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Mon, 13 May 2024 11:51:33 -0500 Subject: [PATCH 2/4] change name --- .../Conversations/IConversationStateService.cs | 2 +- .../Conversations/Services/ConversationStateService.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs index 5663e9a5..de26ef5b 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs @@ -17,6 +17,6 @@ public interface IConversationStateService int activeRounds = -1, string valueType = StateDataType.String, string source = StateSource.User, bool readOnly = false); void SaveStateByArgs(JsonDocument args); bool RemoveState(string name); - void CleanStates(params string[] keepStates); + void CleanStates(params string[] excludedStates); void Save(); } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 4901a7c6..57f09c71 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -270,7 +270,7 @@ public class ConversationStateService : IConversationStateService, IDisposable return true; } - public void CleanStates(params string[] keepStates) + public void CleanStates(params string[] excludedStates) { var routingCtx = _services.GetRequiredService(); var curMsgId = routingCtx.MessageId; @@ -279,7 +279,7 @@ public class ConversationStateService : IConversationStateService, IDisposable foreach (var key in _curStates.Keys) { // skip state - if (keepStates.Contains(key)) + if (excludedStates.Contains(key)) { continue; } From 6024a53476a3b314a7661f03fc7f95e5fc9f74d5 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 13 May 2024 16:00:39 -0500 Subject: [PATCH 3/4] Add Sort parameter to Pagination. --- .../BotSharp.Abstraction/Utilities/Pagination.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs index d11752f6..4e42e2ee 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs @@ -26,6 +26,11 @@ public class Pagination } } + /// + /// Sort by field + /// + public string? Sort { get; set; } + public int Offset { get { return (Page - 1) * Size; } From 1e882e41b24467472bb99ddf1f07e22b9a347e03 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 13 May 2024 16:09:53 -0500 Subject: [PATCH 4/4] Sort order --- .../BotSharp.Abstraction/Utilities/Pagination.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs index 4e42e2ee..92e3eacb 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs @@ -31,6 +31,11 @@ public class Pagination /// public string? Sort { get; set; } + /// + /// Sort order: asc or desc + /// + public string Order { get; set; } = "asc"; + public int Offset { get { return (Page - 1) * Size; }