Skip to content

Commit ed1576f

Browse files
author
Jicheng Lu
committed
refine list loading
1 parent 0beba35 commit ed1576f

25 files changed

Lines changed: 149 additions & 261 deletions

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationStateKeysFilter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class ConversationStateKeysFilter
88
public bool PreLoad { get; set; }
99
public List<string>? AgentIds { get; set; }
1010
public List<string>? UserIds { get; set; }
11+
public DateTime? StartTime { get; set; }
12+
public DateTime? EndTime { get; set; }
1113

1214
public ConversationStateKeysFilter()
1315
{

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/InstructLogKeysFilter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class InstructLogKeysFilter
88
public bool PreLoad { get; set; }
99
public List<string>? AgentIds { get; set; }
1010
public List<string>? UserIds { get; set; }
11+
public DateTime? StartTime { get; set; }
12+
public DateTime? EndTime { get; set; }
1113

1214
public InstructLogKeysFilter()
1315
{

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ bool UpdateRole(Role role, bool updateRoleAgents = false)
5656
void UpdateUserPhone(string userId, string Iphone, string regionCode) => throw new NotImplementedException();
5757
void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
5858
void UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
59-
PagedItems<User> GetUsers(UserFilter filter) => throw new NotImplementedException();
59+
ValueTask<PagedItems<User>> GetUsers(UserFilter filter) => throw new NotImplementedException();
6060
List<User> SearchLoginUsers(User filter, string source = UserSource.Internal) =>throw new NotImplementedException();
6161
User? GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException();
6262
bool UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException();
@@ -93,7 +93,7 @@ bool AppendAgentLabels(string agentId, List<string> labels)
9393
#endregion
9494

9595
#region Agent Task
96-
PagedItems<AgentTask> GetAgentTasks(AgentTaskFilter filter)
96+
ValueTask<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
9797
=> throw new NotImplementedException();
9898
AgentTask? GetAgentTask(string agentId, string taskId)
9999
=> throw new NotImplementedException();
@@ -126,7 +126,7 @@ void UpdateConversationStatus(string conversationId, string status)
126126
=> throw new NotImplementedException();
127127
Conversation GetConversation(string conversationId, bool isLoadStates = false)
128128
=> throw new NotImplementedException();
129-
PagedItems<Conversation> GetConversations(ConversationFilter filter)
129+
ValueTask<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
130130
=> throw new NotImplementedException();
131131
void UpdateConversationTitle(string conversationId, string title)
132132
=> throw new NotImplementedException();
@@ -179,7 +179,7 @@ DateTimePagination<ConversationStateLogModel> GetConversationStateLogs(string co
179179
bool SaveInstructionLogs(IEnumerable<InstructionLogModel> logs)
180180
=> throw new NotImplementedException();
181181

182-
PagedItems<InstructionLogModel> GetInstructionLogs(InstructLogFilter filter)
182+
ValueTask<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
183183
=> throw new NotImplementedException();
184184

185185
List<string> GetInstructionLogSearchKeys(InstructLogKeysFilter filter)
@@ -227,7 +227,7 @@ bool SaveKnolwedgeBaseFileMeta(KnowledgeDocMetaData metaData)
227227
/// <returns></returns>
228228
bool DeleteKnolwedgeBaseFileMeta(string collectionName, string vectorStoreProvider, Guid? fileId = null)
229229
=> throw new NotImplementedException();
230-
PagedItems<KnowledgeDocMetaData> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
230+
ValueTask<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
231231
=> throw new NotImplementedException();
232232
#endregion
233233

@@ -236,7 +236,7 @@ bool UpsertCrontabItem(CrontabItem cron)
236236
=> throw new NotImplementedException();
237237
bool DeleteCrontabItem(string conversationId)
238238
=> throw new NotImplementedException();
239-
PagedItems<CrontabItem> GetCrontabItems(CrontabItemFilter filter)
239+
ValueTask<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
240240
=> throw new NotImplementedException();
241241
#endregion
242242
}

src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace BotSharp.Abstraction.Users;
77
public interface IUserService
88
{
99
Task<User> GetUser(string id);
10+
Task<List<User>> GetUsers(List<string> ids);
1011
Task<PagedItems<User>> GetUsers(UserFilter filter);
1112
Task<List<User>> SearchLoginUsers(User filter);
1213
Task<User?> GetUserDetails(string userId, bool includeAgent = false);

src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public string GetCacheKey()
5050

5151
public class PagedItems<T>
5252
{
53-
public int Count { get; set; }
53+
public long Count { get; set; }
5454
public IEnumerable<T> Items { get; set; } = new List<T>();
5555
}

src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public CrontabService(IServiceProvider services, ILogger<CrontabService> logger)
4444
public async Task<List<CrontabItem>> GetCrontable()
4545
{
4646
var repo = _services.GetRequiredService<IBotSharpRepository>();
47-
var crontable = repo.GetCrontabItems(CrontabItemFilter.Empty());
47+
var crontable = await repo.GetCrontabItems(CrontabItemFilter.Empty());
4848

4949
// Add fixed crontab items from cronsources
5050
var fixedCrantabItems = crontable.Items.ToList();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public async Task<PagedItems<Conversation>> GetConversations(ConversationFilter
8787
}
8888

8989
var db = _services.GetRequiredService<IBotSharpRepository>();
90-
var conversations = db.GetConversations(filter);
90+
var conversations = await db.GetConversations(filter);
9191
return conversations;
9292
}
9393

src/Infrastructure/BotSharp.Core/Loggers/Services/LoggerService.Instruction.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,18 @@ public async Task<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLo
1818

1919
filter.UserIds = !isAdmin && user?.Id != null ? [user.Id] : null;
2020

21-
var agents = new List<Agent>();
2221
var users = new List<User>();
2322

2423
var db = _services.GetRequiredService<IBotSharpRepository>();
25-
var logs = db.GetInstructionLogs(filter);
24+
var agentService = _services.GetRequiredService<IAgentService>();
25+
var logs = await db.GetInstructionLogs(filter);
2626
var agentIds = logs.Items.Where(x => !string.IsNullOrEmpty(x.AgentId)).Select(x => x.AgentId).ToList();
2727
var userIds = logs.Items.Where(x => !string.IsNullOrEmpty(x.UserId)).Select(x => x.UserId).ToList();
28-
agents = db.GetAgents(new AgentFilter
29-
{
30-
AgentIds = agentIds,
31-
Pager = new Pagination { Size = filter.Size }
32-
});
28+
var agents = await agentService.GetAgentOptions(agentIds);
3329

3430
if (isAdmin)
3531
{
36-
users = db.GetUserByIds(userIds);
32+
users = await userService.GetUsers(userIds);
3733
}
3834

3935
var items = logs.Items.Select(x =>
Lines changed: 0 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -1,202 +1,6 @@
1-
using BotSharp.Abstraction.Loggers.Models;
2-
using BotSharp.Abstraction.Plugins.Models;
3-
using BotSharp.Abstraction.Tasks.Models;
4-
using BotSharp.Abstraction.Translation.Models;
5-
using BotSharp.Abstraction.VectorStorage.Models;
6-
71
namespace BotSharp.Core.Repository;
82

93
public class BotSharpDbContext : Database, IBotSharpRepository
104
{
115
public IServiceProvider ServiceProvider => throw new NotImplementedException();
12-
13-
#region Plugin
14-
public PluginConfig GetPluginConfig() => throw new NotImplementedException();
15-
public void SavePluginConfig(PluginConfig config) => throw new NotImplementedException();
16-
#endregion
17-
18-
#region Agent
19-
public Agent GetAgent(string agentId, bool basicsOnly = false)
20-
=> throw new NotImplementedException();
21-
22-
public List<Agent> GetAgents(AgentFilter filter)
23-
=> throw new NotImplementedException();
24-
25-
public List<UserAgent> GetUserAgents(string userId)
26-
=> throw new NotImplementedException();
27-
28-
public void UpdateAgent(Agent agent, AgentField field)
29-
=> throw new NotImplementedException();
30-
31-
public string GetAgentTemplate(string agentId, string templateName)
32-
=> throw new NotImplementedException();
33-
34-
public bool PatchAgentTemplate(string agentId, AgentTemplate template)
35-
=> throw new NotImplementedException();
36-
37-
public List<string> GetAgentResponses(string agentId, string prefix, string intent)
38-
=> throw new NotImplementedException();
39-
40-
public void BulkInsertAgents(List<Agent> agents)
41-
=> throw new NotImplementedException();
42-
43-
public void BulkInsertUserAgents(List<UserAgent> userAgents)
44-
=> throw new NotImplementedException();
45-
46-
public bool DeleteAgents()
47-
=> throw new NotImplementedException();
48-
49-
public bool DeleteAgent(string agentId)
50-
=> throw new NotImplementedException();
51-
#endregion
52-
53-
#region Agent Task
54-
public PagedItems<AgentTask> GetAgentTasks(AgentTaskFilter filter)
55-
=> throw new NotImplementedException();
56-
57-
public AgentTask? GetAgentTask(string agentId, string taskId)
58-
=> throw new NotImplementedException();
59-
60-
public void InsertAgentTask(AgentTask task)
61-
=> throw new NotImplementedException();
62-
63-
public void BulkInsertAgentTasks(List<AgentTask> tasks)
64-
=> throw new NotImplementedException();
65-
66-
public void UpdateAgentTask(AgentTask task, AgentTaskField field)
67-
=> throw new NotImplementedException();
68-
69-
public bool DeleteAgentTask(string agentId, List<string> taskIds)
70-
=> throw new NotImplementedException();
71-
72-
public bool DeleteAgentTasks()
73-
=> throw new NotImplementedException();
74-
#endregion
75-
76-
#region Conversation
77-
public void CreateNewConversation(Conversation conversation)
78-
=> throw new NotImplementedException();
79-
80-
public bool DeleteConversations(IEnumerable<string> conversationIds)
81-
=> throw new NotImplementedException();
82-
83-
public Conversation GetConversation(string conversationId, bool isLoadStates = false)
84-
=> throw new NotImplementedException();
85-
86-
public PagedItems<Conversation> GetConversations(ConversationFilter filter)
87-
=> throw new NotImplementedException();
88-
89-
public List<Conversation> GetLastConversations()
90-
=> throw new NotImplementedException();
91-
92-
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
93-
=> throw new NotImplementedException();
94-
95-
[SideCar]
96-
public List<DialogElement> GetConversationDialogs(string conversationId)
97-
=> throw new NotImplementedException();
98-
99-
public ConversationState GetConversationStates(string conversationId)
100-
=> throw new NotImplementedException();
101-
102-
[SideCar]
103-
public void AppendConversationDialogs(string conversationId, List<DialogElement> dialogs)
104-
=> throw new NotImplementedException();
105-
106-
public void UpdateConversationTitle(string conversationId, string title)
107-
=> throw new NotImplementedException();
108-
public void UpdateConversationTitleAlias(string conversationId, string titleAlias)
109-
=> throw new NotImplementedException();
110-
111-
public bool UpdateConversationTags(string conversationId, List<string> tags)
112-
=> throw new NotImplementedException();
113-
114-
public bool AppendConversationTags(string conversationId, List<string> tags)
115-
=> throw new NotImplementedException();
116-
117-
public bool UpdateConversationMessage(string conversationId, UpdateMessageRequest request)
118-
=> throw new NotImplementedException();
119-
120-
[SideCar]
121-
public void UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint)
122-
=> throw new NotImplementedException();
123-
124-
[SideCar]
125-
public ConversationBreakpoint? GetConversationBreakpoint(string conversationId)
126-
=> throw new NotImplementedException();
127-
128-
public void UpdateConversationStates(string conversationId, List<StateKeyValue> states)
129-
=> throw new NotImplementedException();
130-
131-
public void UpdateConversationStatus(string conversationId, string status)
132-
=> throw new NotImplementedException();
133-
134-
public List<string> TruncateConversation(string conversationId, string messageId, bool cleanLog = false)
135-
=> throw new NotImplementedException();
136-
#endregion
137-
138-
#region LLM Completion Log
139-
public void SaveLlmCompletionLog(LlmCompletionLog log)
140-
{
141-
throw new NotImplementedException();
142-
}
143-
#endregion
144-
145-
#region Conversation Content Log
146-
public void SaveConversationContentLog(ContentLogOutputModel log)
147-
{
148-
throw new NotImplementedException();
149-
}
150-
151-
public List<ContentLogOutputModel> GetConversationContentLogs(string conversationId)
152-
{
153-
throw new NotImplementedException();
154-
}
155-
#endregion
156-
157-
#region Conversation State Log
158-
public void SaveConversationStateLog(ConversationStateLogModel log)
159-
{
160-
throw new NotImplementedException();
161-
}
162-
163-
public List<ConversationStateLogModel> GetConversationStateLogs(string conversationId)
164-
{
165-
throw new NotImplementedException();
166-
}
167-
#endregion
168-
169-
#region Stats
170-
public void IncrementConversationCount()
171-
{
172-
throw new NotImplementedException();
173-
}
174-
#endregion
175-
176-
#region Translation
177-
public IEnumerable<TranslationMemoryOutput> GetTranslationMemories(IEnumerable<TranslationMemoryQuery> queries)
178-
=> throw new NotImplementedException();
179-
public bool SaveTranslationMemories(IEnumerable<TranslationMemoryInput> inputs) =>
180-
throw new NotImplementedException();
181-
#endregion
182-
183-
#region KnowledgeBase
184-
public bool AddKnowledgeCollectionConfigs(List<VectorCollectionConfig> configs, bool reset = false) =>
185-
throw new NotImplementedException();
186-
187-
public bool DeleteKnowledgeCollectionConfig(string collectionName) =>
188-
throw new NotImplementedException();
189-
190-
public IEnumerable<VectorCollectionConfig> GetKnowledgeCollectionConfigs(VectorCollectionConfigFilter filter) =>
191-
throw new NotImplementedException();
192-
193-
public bool SaveKnolwedgeBaseFileMeta(KnowledgeDocMetaData metaData) =>
194-
throw new NotImplementedException();
195-
196-
public bool DeleteKnolwedgeBaseFileMeta(string collectionName, string vectorStoreProvider, Guid? fileId = null) =>
197-
throw new NotImplementedException();
198-
199-
public PagedItems<KnowledgeDocMetaData> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter) =>
200-
throw new NotImplementedException();
201-
#endregion
2026
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace BotSharp.Core.Repository;
66
public partial class FileRepository
77
{
88
#region Task
9-
public PagedItems<AgentTask> GetAgentTasks(AgentTaskFilter filter)
9+
public async ValueTask<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
1010
{
1111
if (filter == null)
1212
{

0 commit comments

Comments
 (0)