refine list loading
This commit is contained in:
parent
0beba35a80
commit
ed1576f7e0
|
|
@ -8,6 +8,8 @@ public class ConversationStateKeysFilter
|
|||
public bool PreLoad { get; set; }
|
||||
public List<string>? AgentIds { get; set; }
|
||||
public List<string>? UserIds { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
|
||||
public ConversationStateKeysFilter()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ public class InstructLogKeysFilter
|
|||
public bool PreLoad { get; set; }
|
||||
public List<string>? AgentIds { get; set; }
|
||||
public List<string>? UserIds { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
|
||||
public InstructLogKeysFilter()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
void UpdateUserPhone(string userId, string Iphone, string regionCode) => throw new NotImplementedException();
|
||||
void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
|
||||
void UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
|
||||
PagedItems<User> GetUsers(UserFilter filter) => throw new NotImplementedException();
|
||||
ValueTask<PagedItems<User>> GetUsers(UserFilter filter) => throw new NotImplementedException();
|
||||
List<User> SearchLoginUsers(User filter, string source = UserSource.Internal) =>throw new NotImplementedException();
|
||||
User? GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException();
|
||||
bool UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException();
|
||||
|
|
@ -93,7 +93,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
#endregion
|
||||
|
||||
#region Agent Task
|
||||
PagedItems<AgentTask> GetAgentTasks(AgentTaskFilter filter)
|
||||
ValueTask<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
|
||||
=> throw new NotImplementedException();
|
||||
AgentTask? GetAgentTask(string agentId, string taskId)
|
||||
=> throw new NotImplementedException();
|
||||
|
|
@ -126,7 +126,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
=> throw new NotImplementedException();
|
||||
Conversation GetConversation(string conversationId, bool isLoadStates = false)
|
||||
=> throw new NotImplementedException();
|
||||
PagedItems<Conversation> GetConversations(ConversationFilter filter)
|
||||
ValueTask<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
|
||||
=> throw new NotImplementedException();
|
||||
void UpdateConversationTitle(string conversationId, string title)
|
||||
=> throw new NotImplementedException();
|
||||
|
|
@ -179,7 +179,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
bool SaveInstructionLogs(IEnumerable<InstructionLogModel> logs)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
PagedItems<InstructionLogModel> GetInstructionLogs(InstructLogFilter filter)
|
||||
ValueTask<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
List<string> GetInstructionLogSearchKeys(InstructLogKeysFilter filter)
|
||||
|
|
@ -227,7 +227,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
/// <returns></returns>
|
||||
bool DeleteKnolwedgeBaseFileMeta(string collectionName, string vectorStoreProvider, Guid? fileId = null)
|
||||
=> throw new NotImplementedException();
|
||||
PagedItems<KnowledgeDocMetaData> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
|
||||
ValueTask<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
|
||||
=> throw new NotImplementedException();
|
||||
#endregion
|
||||
|
||||
|
|
@ -236,7 +236,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
=> throw new NotImplementedException();
|
||||
bool DeleteCrontabItem(string conversationId)
|
||||
=> throw new NotImplementedException();
|
||||
PagedItems<CrontabItem> GetCrontabItems(CrontabItemFilter filter)
|
||||
ValueTask<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
|
||||
=> throw new NotImplementedException();
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace BotSharp.Abstraction.Users;
|
|||
public interface IUserService
|
||||
{
|
||||
Task<User> GetUser(string id);
|
||||
Task<List<User>> GetUsers(List<string> ids);
|
||||
Task<PagedItems<User>> GetUsers(UserFilter filter);
|
||||
Task<List<User>> SearchLoginUsers(User filter);
|
||||
Task<User?> GetUserDetails(string userId, bool includeAgent = false);
|
||||
|
|
|
|||
|
|
@ -50,6 +50,6 @@ public class Pagination : ICacheKey
|
|||
|
||||
public class PagedItems<T>
|
||||
{
|
||||
public int Count { get; set; }
|
||||
public long Count { get; set; }
|
||||
public IEnumerable<T> Items { get; set; } = new List<T>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class CrontabService : ICrontabService, ITaskFeeder
|
|||
public async Task<List<CrontabItem>> GetCrontable()
|
||||
{
|
||||
var repo = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var crontable = repo.GetCrontabItems(CrontabItemFilter.Empty());
|
||||
var crontable = await repo.GetCrontabItems(CrontabItemFilter.Empty());
|
||||
|
||||
// Add fixed crontab items from cronsources
|
||||
var fixedCrantabItems = crontable.Items.ToList();
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public partial class ConversationService : IConversationService
|
|||
}
|
||||
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var conversations = db.GetConversations(filter);
|
||||
var conversations = await db.GetConversations(filter);
|
||||
return conversations;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,22 +18,18 @@ public partial class LoggerService
|
|||
|
||||
filter.UserIds = !isAdmin && user?.Id != null ? [user.Id] : null;
|
||||
|
||||
var agents = new List<Agent>();
|
||||
var users = new List<User>();
|
||||
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var logs = db.GetInstructionLogs(filter);
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var logs = await db.GetInstructionLogs(filter);
|
||||
var agentIds = logs.Items.Where(x => !string.IsNullOrEmpty(x.AgentId)).Select(x => x.AgentId).ToList();
|
||||
var userIds = logs.Items.Where(x => !string.IsNullOrEmpty(x.UserId)).Select(x => x.UserId).ToList();
|
||||
agents = db.GetAgents(new AgentFilter
|
||||
{
|
||||
AgentIds = agentIds,
|
||||
Pager = new Pagination { Size = filter.Size }
|
||||
});
|
||||
var agents = await agentService.GetAgentOptions(agentIds);
|
||||
|
||||
if (isAdmin)
|
||||
{
|
||||
users = db.GetUserByIds(userIds);
|
||||
users = await userService.GetUsers(userIds);
|
||||
}
|
||||
|
||||
var items = logs.Items.Select(x =>
|
||||
|
|
|
|||
|
|
@ -1,202 +1,6 @@
|
|||
using BotSharp.Abstraction.Loggers.Models;
|
||||
using BotSharp.Abstraction.Plugins.Models;
|
||||
using BotSharp.Abstraction.Tasks.Models;
|
||||
using BotSharp.Abstraction.Translation.Models;
|
||||
using BotSharp.Abstraction.VectorStorage.Models;
|
||||
|
||||
namespace BotSharp.Core.Repository;
|
||||
|
||||
public class BotSharpDbContext : Database, IBotSharpRepository
|
||||
{
|
||||
public IServiceProvider ServiceProvider => throw new NotImplementedException();
|
||||
|
||||
#region Plugin
|
||||
public PluginConfig GetPluginConfig() => throw new NotImplementedException();
|
||||
public void SavePluginConfig(PluginConfig config) => throw new NotImplementedException();
|
||||
#endregion
|
||||
|
||||
#region Agent
|
||||
public Agent GetAgent(string agentId, bool basicsOnly = false)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public List<Agent> GetAgents(AgentFilter filter)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public List<UserAgent> GetUserAgents(string userId)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public void UpdateAgent(Agent agent, AgentField field)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public string GetAgentTemplate(string agentId, string templateName)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public bool PatchAgentTemplate(string agentId, AgentTemplate template)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public List<string> GetAgentResponses(string agentId, string prefix, string intent)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public void BulkInsertAgents(List<Agent> agents)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public void BulkInsertUserAgents(List<UserAgent> userAgents)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public bool DeleteAgents()
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public bool DeleteAgent(string agentId)
|
||||
=> throw new NotImplementedException();
|
||||
#endregion
|
||||
|
||||
#region Agent Task
|
||||
public PagedItems<AgentTask> GetAgentTasks(AgentTaskFilter filter)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public AgentTask? GetAgentTask(string agentId, string taskId)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public void InsertAgentTask(AgentTask task)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public void BulkInsertAgentTasks(List<AgentTask> tasks)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public void UpdateAgentTask(AgentTask task, AgentTaskField field)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public bool DeleteAgentTask(string agentId, List<string> taskIds)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public bool DeleteAgentTasks()
|
||||
=> throw new NotImplementedException();
|
||||
#endregion
|
||||
|
||||
#region Conversation
|
||||
public void CreateNewConversation(Conversation conversation)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public bool DeleteConversations(IEnumerable<string> conversationIds)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Conversation GetConversation(string conversationId, bool isLoadStates = false)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public PagedItems<Conversation> GetConversations(ConversationFilter filter)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public List<Conversation> GetLastConversations()
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
[SideCar]
|
||||
public List<DialogElement> GetConversationDialogs(string conversationId)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public ConversationState GetConversationStates(string conversationId)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
[SideCar]
|
||||
public void AppendConversationDialogs(string conversationId, List<DialogElement> dialogs)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public void UpdateConversationTitle(string conversationId, string title)
|
||||
=> throw new NotImplementedException();
|
||||
public void UpdateConversationTitleAlias(string conversationId, string titleAlias)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public bool UpdateConversationTags(string conversationId, List<string> tags)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public bool AppendConversationTags(string conversationId, List<string> tags)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public bool UpdateConversationMessage(string conversationId, UpdateMessageRequest request)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
[SideCar]
|
||||
public void UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
[SideCar]
|
||||
public ConversationBreakpoint? GetConversationBreakpoint(string conversationId)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public void UpdateConversationStates(string conversationId, List<StateKeyValue> states)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public void UpdateConversationStatus(string conversationId, string status)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public List<string> TruncateConversation(string conversationId, string messageId, bool cleanLog = false)
|
||||
=> throw new NotImplementedException();
|
||||
#endregion
|
||||
|
||||
#region LLM Completion Log
|
||||
public void SaveLlmCompletionLog(LlmCompletionLog log)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Conversation Content Log
|
||||
public void SaveConversationContentLog(ContentLogOutputModel log)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<ContentLogOutputModel> GetConversationContentLogs(string conversationId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Conversation State Log
|
||||
public void SaveConversationStateLog(ConversationStateLogModel log)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<ConversationStateLogModel> GetConversationStateLogs(string conversationId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Stats
|
||||
public void IncrementConversationCount()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Translation
|
||||
public IEnumerable<TranslationMemoryOutput> GetTranslationMemories(IEnumerable<TranslationMemoryQuery> queries)
|
||||
=> throw new NotImplementedException();
|
||||
public bool SaveTranslationMemories(IEnumerable<TranslationMemoryInput> inputs) =>
|
||||
throw new NotImplementedException();
|
||||
#endregion
|
||||
|
||||
#region KnowledgeBase
|
||||
public bool AddKnowledgeCollectionConfigs(List<VectorCollectionConfig> configs, bool reset = false) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
public bool DeleteKnowledgeCollectionConfig(string collectionName) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
public IEnumerable<VectorCollectionConfig> GetKnowledgeCollectionConfigs(VectorCollectionConfigFilter filter) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
public bool SaveKnolwedgeBaseFileMeta(KnowledgeDocMetaData metaData) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
public bool DeleteKnolwedgeBaseFileMeta(string collectionName, string vectorStoreProvider, Guid? fileId = null) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
public PagedItems<KnowledgeDocMetaData> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter) =>
|
||||
throw new NotImplementedException();
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace BotSharp.Core.Repository;
|
|||
public partial class FileRepository
|
||||
{
|
||||
#region Task
|
||||
public PagedItems<AgentTask> GetAgentTasks(AgentTaskFilter filter)
|
||||
public async ValueTask<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ public partial class FileRepository
|
|||
return record;
|
||||
}
|
||||
|
||||
public PagedItems<Conversation> GetConversations(ConversationFilter filter)
|
||||
public async ValueTask<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
|
|
@ -546,7 +546,7 @@ public partial class FileRepository
|
|||
return new PagedItems<Conversation>
|
||||
{
|
||||
Items = records.OrderByDescending(x => x.CreatedTime).Skip(pager.Offset).Take(pager.Size),
|
||||
Count = records.Count(),
|
||||
Count = records.Count()
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -708,7 +708,9 @@ public partial class FileRepository
|
|||
if (conv == null
|
||||
|| states.IsNullOrEmpty()
|
||||
|| (!filter.AgentIds.IsNullOrEmpty() && !filter.AgentIds.Contains(conv.AgentId))
|
||||
|| (!filter.UserIds.IsNullOrEmpty() && !filter.UserIds.Contains(conv.UserId)))
|
||||
|| (!filter.UserIds.IsNullOrEmpty() && !filter.UserIds.Contains(conv.UserId))
|
||||
|| (filter.StartTime.HasValue && conv.CreatedTime < filter.StartTime.Value)
|
||||
|| (filter.EndTime.HasValue && conv.CreatedTime > filter.EndTime.Value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public partial class FileRepository
|
|||
}
|
||||
|
||||
|
||||
public PagedItems<CrontabItem> GetCrontabItems(CrontabItemFilter filter)
|
||||
public async ValueTask<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
|
||||
{
|
||||
|
||||
if (filter == null)
|
||||
|
|
@ -111,7 +111,7 @@ public partial class FileRepository
|
|||
return new PagedItems<CrontabItem>
|
||||
{
|
||||
Items = records.OrderByDescending(x => x.CreatedTime).Skip(filter.Offset).Take(filter.Size),
|
||||
Count = records.Count(),
|
||||
Count = records.Count()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ public partial class FileRepository
|
|||
return true;
|
||||
}
|
||||
|
||||
public PagedItems<KnowledgeDocMetaData> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
|
||||
public async ValueTask<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(collectionName)
|
||||
|| string.IsNullOrWhiteSpace(vectorStoreProvider))
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ namespace BotSharp.Core.Repository
|
|||
return true;
|
||||
}
|
||||
|
||||
public PagedItems<InstructionLogModel> GetInstructionLogs(InstructLogFilter filter)
|
||||
public async ValueTask<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
|
|
@ -316,7 +316,9 @@ namespace BotSharp.Core.Repository
|
|||
if (log == null
|
||||
|| log.InnerStates.IsNullOrEmpty()
|
||||
|| (!filter.UserIds.IsNullOrEmpty() && !filter.UserIds.Contains(log.UserId))
|
||||
|| (!filter.AgentIds.IsNullOrEmpty() && !filter.AgentIds.Contains(log.AgentId)))
|
||||
|| (!filter.AgentIds.IsNullOrEmpty() && !filter.AgentIds.Contains(log.AgentId))
|
||||
|| (filter.StartTime.HasValue && log.CreatedTime < filter.StartTime.Value)
|
||||
|| (filter.EndTime.HasValue && log.CreatedTime > filter.EndTime.Value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public partial class FileRepository
|
|||
File.WriteAllText(path, JsonSerializer.Serialize(user, _options));
|
||||
}
|
||||
|
||||
public PagedItems<User> GetUsers(UserFilter filter)
|
||||
public async ValueTask<PagedItems<User>> GetUsers(UserFilter filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class AgentTaskService : IAgentTaskService
|
|||
else
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var pagedTasks = db.GetAgentTasks(filter);
|
||||
var pagedTasks = await db.GetAgentTasks(filter);
|
||||
return await Task.FromResult(pagedTasks);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -411,10 +411,18 @@ public class UserService : IUserService
|
|||
return user;
|
||||
}
|
||||
|
||||
[SharpCache(10)]
|
||||
public async Task<List<User>> GetUsers(List<string> ids)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var users = db.GetUserByIds(ids);
|
||||
return users;
|
||||
}
|
||||
|
||||
public async Task<PagedItems<User>> GetUsers(UserFilter filter)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var users = db.GetUsers(filter);
|
||||
var users = await db.GetUsers(filter);
|
||||
return users;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,11 +66,11 @@ public class ConversationController : ControllerBase
|
|||
var agents = await agentService.GetAgentOptions(agentIds);
|
||||
|
||||
var userIds = list.Select(x => x.User.Id).ToList();
|
||||
var users = await userService.GetUsers(new UserFilter { UserIds = userIds, Size = filter.Pager.Size });
|
||||
var users = await userService.GetUsers(userIds);
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
user = users.Items.FirstOrDefault(x => x.Id == item.User.Id);
|
||||
user = users.FirstOrDefault(x => x.Id == item.User.Id);
|
||||
item.User = UserViewModel.FromUser(user);
|
||||
var agent = agents.FirstOrDefault(x => x.Id == item.AgentId);
|
||||
item.AgentName = agent?.Name ?? "Unkown";
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ public partial class KnowledgeService
|
|||
var vectorStoreProvider = _settings.VectorDb.Provider;
|
||||
|
||||
// Get doc meta data
|
||||
var pageData = db.GetKnowledgeBaseFileMeta(collectionName, vectorStoreProvider, new KnowledgeFileFilter
|
||||
var pageData = await db.GetKnowledgeBaseFileMeta(collectionName, vectorStoreProvider, new KnowledgeFileFilter
|
||||
{
|
||||
Size = 1,
|
||||
FileIds = [ fileId ]
|
||||
|
|
@ -281,7 +281,7 @@ public partial class KnowledgeService
|
|||
var vectorStoreProvider = _settings.VectorDb.Provider;
|
||||
|
||||
// Get doc meta data
|
||||
var pagedData = db.GetKnowledgeBaseFileMeta(collectionName, vectorStoreProvider, filter);
|
||||
var pagedData = await db.GetKnowledgeBaseFileMeta(collectionName, vectorStoreProvider, filter);
|
||||
|
||||
var files = pagedData.Items?.Select(x => new KnowledgeFileModel
|
||||
{
|
||||
|
|
@ -308,7 +308,7 @@ public partial class KnowledgeService
|
|||
var vectorStoreProvider = _settings.VectorDb.Provider;
|
||||
|
||||
// Get doc binary data
|
||||
var pageData = db.GetKnowledgeBaseFileMeta(collectionName, vectorStoreProvider, new KnowledgeFileFilter
|
||||
var pageData = await db.GetKnowledgeBaseFileMeta(collectionName, vectorStoreProvider, new KnowledgeFileFilter
|
||||
{
|
||||
Size = 1,
|
||||
FileIds = [ fileId ]
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace BotSharp.Plugin.MongoStorage.Repository;
|
|||
public partial class MongoRepository
|
||||
{
|
||||
#region Task
|
||||
public PagedItems<AgentTask> GetAgentTasks(AgentTaskFilter filter)
|
||||
public async ValueTask<PagedItems<AgentTask>> GetAgentTasks(AgentTaskFilter filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
|
|
@ -34,13 +34,23 @@ public partial class MongoRepository
|
|||
|
||||
var filterDef = builder.And(filters);
|
||||
var sortDef = Builders<AgentTaskDocument>.Sort.Descending(x => x.CreatedTime);
|
||||
var totalTasks = _dc.AgentTasks.CountDocuments(filterDef);
|
||||
var taskDocs = _dc.AgentTasks.Find(filterDef).Sort(sortDef).Skip(pager.Offset).Limit(pager.Size).ToList();
|
||||
|
||||
var agentIds = taskDocs.Select(x => x.AgentId).Distinct().ToList();
|
||||
var docsTask = _dc.AgentTasks.FindAsync(filterDef, options: new()
|
||||
{
|
||||
Sort = sortDef,
|
||||
Skip = pager.Offset,
|
||||
Limit = pager.Size
|
||||
});
|
||||
var countTask = _dc.AgentTasks.CountDocumentsAsync(filterDef);
|
||||
await Task.WhenAll([docsTask, countTask]);
|
||||
|
||||
var docs = docsTask.Result.ToList();
|
||||
var count = countTask.Result;
|
||||
|
||||
var agentIds = docs.Select(x => x.AgentId).Distinct().ToList();
|
||||
var agents = GetAgents(new AgentFilter { AgentIds = agentIds });
|
||||
|
||||
var tasks = taskDocs.Select(x =>
|
||||
var tasks = docs.Select(x =>
|
||||
{
|
||||
var task = AgentTaskDocument.ToDomainModel(x);
|
||||
task.Agent = agents.FirstOrDefault(a => a.Id == x.AgentId);
|
||||
|
|
@ -50,7 +60,7 @@ public partial class MongoRepository
|
|||
return new PagedItems<AgentTask>
|
||||
{
|
||||
Items = tasks,
|
||||
Count = (int)totalTasks
|
||||
Count = count
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -336,7 +336,7 @@ public partial class MongoRepository
|
|||
};
|
||||
}
|
||||
|
||||
public PagedItems<Conversation> GetConversations(ConversationFilter filter)
|
||||
public async ValueTask<PagedItems<Conversation>> GetConversations(ConversationFilter filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
|
|
@ -466,10 +466,19 @@ public partial class MongoRepository
|
|||
}
|
||||
}
|
||||
|
||||
var conversationDocs = _dc.Conversations.Find(filterDef).Sort(sortDef).Skip(pager.Offset).Limit(pager.Size).ToList();
|
||||
var count = _dc.Conversations.CountDocuments(filterDef);
|
||||
var docsTask = _dc.Conversations.FindAsync(filterDef, options: new()
|
||||
{
|
||||
Sort = sortDef,
|
||||
Skip = pager.Offset,
|
||||
Limit = pager.Size
|
||||
});
|
||||
var countTask = _dc.Conversations.CountDocumentsAsync(filterDef);
|
||||
await Task.WhenAll([docsTask, countTask]);
|
||||
|
||||
var conversations = conversationDocs.Select(x =>
|
||||
var docs = docsTask.Result.ToList();
|
||||
var count = countTask.Result;
|
||||
|
||||
var conversations = docs.Select(x =>
|
||||
{
|
||||
var states = new Dictionary<string, string>();
|
||||
if (filter.IsLoadLatestStates)
|
||||
|
|
@ -502,7 +511,7 @@ public partial class MongoRepository
|
|||
return new PagedItems<Conversation>
|
||||
{
|
||||
Items = conversations,
|
||||
Count = (int)count
|
||||
Count = count
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -693,11 +702,18 @@ public partial class MongoRepository
|
|||
{
|
||||
filters.Add(builder.In(x => x.AgentId, filter.AgentIds));
|
||||
}
|
||||
|
||||
if (!filter.UserIds.IsNullOrEmpty())
|
||||
{
|
||||
filters.Add(builder.In(x => x.UserId, filter.UserIds));
|
||||
}
|
||||
if (filter.StartTime.HasValue)
|
||||
{
|
||||
filters.Add(builder.Gte(x => x.CreatedTime, filter.StartTime.Value));
|
||||
}
|
||||
if (filter.EndTime.HasValue)
|
||||
{
|
||||
filters.Add(builder.Lte(x => x.CreatedTime, filter.EndTime.Value));
|
||||
}
|
||||
|
||||
var convDocs = _dc.Conversations.Find(builder.And(filters))
|
||||
.Sort(sortDef)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public partial class MongoRepository
|
|||
}
|
||||
|
||||
|
||||
public PagedItems<CrontabItem> GetCrontabItems(CrontabItemFilter filter)
|
||||
public async ValueTask<PagedItems<CrontabItem>> GetCrontabItems(CrontabItemFilter filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
|
|
@ -73,15 +73,24 @@ public partial class MongoRepository
|
|||
var filterDef = cronBuilder.And(cronFilters);
|
||||
var sortDef = Builders<CrontabItemDocument>.Sort.Descending(x => x.CreatedTime);
|
||||
|
||||
var cronDocs = _dc.CrontabItems.Find(filterDef).Sort(sortDef).Skip(filter.Offset).Limit(filter.Size).ToList();
|
||||
var count = _dc.CrontabItems.CountDocuments(filterDef);
|
||||
var docsTask = _dc.CrontabItems.FindAsync(filterDef, options: new()
|
||||
{
|
||||
Sort = sortDef,
|
||||
Skip = filter.Offset,
|
||||
Limit = filter.Size
|
||||
});
|
||||
var countTask = _dc.CrontabItems.CountDocumentsAsync(filterDef);
|
||||
await Task.WhenAll([docsTask, countTask]);
|
||||
|
||||
var crontabItems = cronDocs.Select(x => CrontabItemDocument.ToDomainModel(x)).ToList();
|
||||
var docs = docsTask.Result.ToList();
|
||||
var count = countTask.Result;
|
||||
|
||||
var crontabItems = docs.Select(x => CrontabItemDocument.ToDomainModel(x)).ToList();
|
||||
|
||||
return new PagedItems<CrontabItem>
|
||||
{
|
||||
Items = crontabItems,
|
||||
Count = (int)count
|
||||
Count = count
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ public partial class MongoRepository
|
|||
return res.DeletedCount > 0;
|
||||
}
|
||||
|
||||
public PagedItems<KnowledgeDocMetaData> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
|
||||
public async ValueTask<PagedItems<KnowledgeDocMetaData>> GetKnowledgeBaseFileMeta(string collectionName, string vectorStoreProvider, KnowledgeFileFilter filter)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(collectionName)
|
||||
|| string.IsNullOrWhiteSpace(vectorStoreProvider))
|
||||
|
|
@ -209,8 +209,18 @@ public partial class MongoRepository
|
|||
|
||||
var filterDef = builder.And(docFilters);
|
||||
var sortDef = Builders<KnowledgeCollectionFileMetaDocument>.Sort.Descending(x => x.CreatedDate);
|
||||
var docs = _dc.KnowledgeCollectionFileMeta.Find(filterDef).Sort(sortDef).Skip(filter.Offset).Limit(filter.Size).ToList();
|
||||
var count = _dc.KnowledgeCollectionFileMeta.CountDocuments(filterDef);
|
||||
|
||||
var docsTask = _dc.KnowledgeCollectionFileMeta.FindAsync(filterDef, options: new()
|
||||
{
|
||||
Sort = sortDef,
|
||||
Skip = filter.Offset,
|
||||
Limit = filter.Size
|
||||
});
|
||||
var countTask = _dc.KnowledgeCollectionFileMeta.CountDocumentsAsync(filterDef);
|
||||
await Task.WhenAll([docsTask, countTask]);
|
||||
|
||||
var docs = docsTask.Result.ToList();
|
||||
var count = countTask.Result;
|
||||
|
||||
var files = docs?.Select(x => new KnowledgeDocMetaData
|
||||
{
|
||||
|
|
@ -229,7 +239,7 @@ public partial class MongoRepository
|
|||
return new PagedItems<KnowledgeDocMetaData>
|
||||
{
|
||||
Items = files,
|
||||
Count = (int)count
|
||||
Count = count
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ public partial class MongoRepository
|
|||
return true;
|
||||
}
|
||||
|
||||
public PagedItems<InstructionLogModel> GetInstructionLogs(InstructLogFilter filter)
|
||||
public async ValueTask<PagedItems<InstructionLogModel>> GetInstructionLogs(InstructLogFilter filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
|
|
@ -251,8 +251,18 @@ public partial class MongoRepository
|
|||
|
||||
var filterDef = logBuilder.And(logFilters);
|
||||
var sortDef = Builders<InstructionLogDocument>.Sort.Descending(x => x.CreatedTime);
|
||||
var docs = _dc.InstructionLogs.Find(filterDef).Sort(sortDef).Skip(filter.Offset).Limit(filter.Size).ToList();
|
||||
var count = _dc.InstructionLogs.CountDocuments(filterDef);
|
||||
|
||||
var docsTask = _dc.InstructionLogs.FindAsync(filterDef, options: new()
|
||||
{
|
||||
Sort = sortDef,
|
||||
Skip = filter.Offset,
|
||||
Limit = filter.Size
|
||||
});
|
||||
var countTask = _dc.InstructionLogs.CountDocumentsAsync(filterDef);
|
||||
await Task.WhenAll([docsTask, countTask]);
|
||||
|
||||
var docs = docsTask.Result.ToList();
|
||||
var count = countTask.Result;
|
||||
|
||||
var logs = docs.Select(x =>
|
||||
{
|
||||
|
|
@ -270,7 +280,7 @@ public partial class MongoRepository
|
|||
return new PagedItems<InstructionLogModel>
|
||||
{
|
||||
Items = logs,
|
||||
Count = (int)count
|
||||
Count = count
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -288,11 +298,18 @@ public partial class MongoRepository
|
|||
{
|
||||
filters.Add(builder.In(x => x.AgentId, filter.AgentIds));
|
||||
}
|
||||
|
||||
if (!filter.UserIds.IsNullOrEmpty())
|
||||
{
|
||||
filters.Add(builder.In(x => x.UserId, filter.UserIds));
|
||||
}
|
||||
if (filter.StartTime.HasValue)
|
||||
{
|
||||
filters.Add(builder.Gte(x => x.CreatedTime, filter.StartTime.Value));
|
||||
}
|
||||
if (filter.EndTime.HasValue)
|
||||
{
|
||||
filters.Add(builder.Lte(x => x.CreatedTime, filter.EndTime.Value));
|
||||
}
|
||||
|
||||
var convDocs = _dc.InstructionLogs.Find(builder.And(filters))
|
||||
.Sort(sortDef)
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ public partial class MongoRepository
|
|||
}
|
||||
}
|
||||
|
||||
public PagedItems<User> GetUsers(UserFilter filter)
|
||||
public async ValueTask<PagedItems<User>> GetUsers(UserFilter filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
|
|
@ -246,14 +246,23 @@ public partial class MongoRepository
|
|||
var sortDef = Builders<UserDocument>.Sort.Descending(x => x.CreatedTime);
|
||||
|
||||
// Search
|
||||
var userDocs = _dc.Users.Find(filterDef).Sort(sortDef).Skip(filter.Offset).Limit(filter.Size).ToList();
|
||||
var count = _dc.Users.CountDocuments(filterDef);
|
||||
var docsTask = _dc.Users.FindAsync(filterDef, options: new()
|
||||
{
|
||||
Sort = sortDef,
|
||||
Skip = filter.Offset,
|
||||
Limit = filter.Size
|
||||
});
|
||||
var countTask = _dc.Users.CountDocumentsAsync(filterDef);
|
||||
await Task.WhenAll([docsTask, countTask]);
|
||||
|
||||
var users = userDocs.Select(x => x.ToUser()).ToList();
|
||||
var docs = docsTask.Result.ToList();
|
||||
var count = countTask.Result;
|
||||
|
||||
var users = docs.Select(x => x.ToUser()).ToList();
|
||||
return new PagedItems<User>
|
||||
{
|
||||
Items = users,
|
||||
Count = (int)count
|
||||
Count = count
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue