Skip to content

Commit 433e302

Browse files
authored
Merge pull request #920 from iceljc/master
refine document
2 parents 8fd5ac1 + 6c735a0 commit 433e302

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginMenuDef.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class PluginMenuDef(string label, string? link = null, string? icon = nul
1313
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
1414
public string? Link { get; set; } = link;
1515

16+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
17+
public string? IFrameUrl { get; set; }
18+
1619
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
1720
public bool? IsHeader { get; set; }
1821

src/Plugins/BotSharp.Plugin.MongoStorage/Collections/InstructionLogBetaDocument.cs renamed to src/Plugins/BotSharp.Plugin.MongoStorage/Collections/InstructionLogDocument.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BotSharp.Plugin.MongoStorage.Collections;
44

5-
public class InstructionLogBetaDocument : MongoBase
5+
public class InstructionLogDocument : MongoBase
66
{
77
public string? AgentId { get; set; }
88
public string Provider { get; set; } = default!;
@@ -15,9 +15,9 @@ public class InstructionLogBetaDocument : MongoBase
1515
public Dictionary<string, BsonDocument> States { get; set; } = new();
1616
public DateTime CreatedTime { get; set; }
1717

18-
public static InstructionLogBetaDocument ToMongoModel(InstructionLogModel log)
18+
public static InstructionLogDocument ToMongoModel(InstructionLogModel log)
1919
{
20-
return new InstructionLogBetaDocument
20+
return new InstructionLogDocument
2121
{
2222
AgentId = log.AgentId,
2323
Provider = log.Provider,
@@ -31,7 +31,7 @@ public static InstructionLogBetaDocument ToMongoModel(InstructionLogModel log)
3131
};
3232
}
3333

34-
public static InstructionLogModel ToDomainModel(InstructionLogBetaDocument log)
34+
public static InstructionLogModel ToDomainModel(InstructionLogDocument log)
3535
{
3636
return new InstructionLogModel
3737
{

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private IMongoCollection<ConversationContentLogDocument> CreateContentLogIndex()
115115
{
116116
var collection = GetCollectionOrCreate<ConversationContentLogDocument>("ConversationContentLogs");
117117
var indexes = collection.Indexes.List().ToList();
118-
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreateTime"));
118+
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreatedTime"));
119119
if (createTimeIndex == null)
120120
{
121121
var indexDef = Builders<ConversationContentLogDocument>.IndexKeys.Ascending(x => x.CreatedTime);
@@ -128,14 +128,27 @@ private IMongoCollection<ConversationStateLogDocument> CreateStateLogIndex()
128128
{
129129
var collection = GetCollectionOrCreate<ConversationStateLogDocument>("ConversationStateLogs");
130130
var indexes = collection.Indexes.List().ToList();
131-
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreateTime"));
131+
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreatedTime"));
132132
if (createTimeIndex == null)
133133
{
134134
var indexDef = Builders<ConversationStateLogDocument>.IndexKeys.Ascending(x => x.CreatedTime);
135135
collection.Indexes.CreateOne(new CreateIndexModel<ConversationStateLogDocument>(indexDef));
136136
}
137137
return collection;
138138
}
139+
140+
private IMongoCollection<InstructionLogDocument> CreateInstructionLogIndex()
141+
{
142+
var collection = GetCollectionOrCreate<InstructionLogDocument>("InstructionLogs");
143+
var indexes = collection.Indexes.List().ToList();
144+
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreatedTime"));
145+
if (createTimeIndex == null)
146+
{
147+
var indexDef = Builders<InstructionLogDocument>.IndexKeys.Descending(x => x.CreatedTime);
148+
collection.Indexes.CreateOne(new CreateIndexModel<InstructionLogDocument>(indexDef));
149+
}
150+
return collection;
151+
}
139152
#endregion
140153
#endregion
141154

@@ -193,6 +206,6 @@ public IMongoCollection<CrontabItemDocument> CrontabItems
193206
public IMongoCollection<GlobalStatisticsDocument> GlobalStatistics
194207
=> GetCollectionOrCreate<GlobalStatisticsDocument>("GlobalStatistics");
195208

196-
public IMongoCollection<InstructionLogBetaDocument> InstructionLogs
197-
=> GetCollectionOrCreate<InstructionLogBetaDocument>("InstructionLogs");
209+
public IMongoCollection<InstructionLogDocument> InstructionLogs
210+
=> CreateInstructionLogIndex();
198211
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ public bool SaveInstructionLogs(IEnumerable<InstructionLogModel> logs)
119119
{
120120
if (logs.IsNullOrEmpty()) return false;
121121

122-
var docs = new List<InstructionLogBetaDocument>();
122+
var docs = new List<InstructionLogDocument>();
123123
foreach (var log in logs)
124124
{
125-
var doc = InstructionLogBetaDocument.ToMongoModel(log);
125+
var doc = InstructionLogDocument.ToMongoModel(log);
126126
foreach (var pair in log.States)
127127
{
128128
try
@@ -152,8 +152,8 @@ public PagedItems<InstructionLogModel> GetInstructionLogs(InstructLogFilter filt
152152
filter = InstructLogFilter.Empty();
153153
}
154154

155-
var builder = Builders<InstructionLogBetaDocument>.Filter;
156-
var filters = new List<FilterDefinition<InstructionLogBetaDocument>>() { builder.Empty };
155+
var builder = Builders<InstructionLogDocument>.Filter;
156+
var filters = new List<FilterDefinition<InstructionLogDocument>>() { builder.Empty };
157157

158158
// Filter logs
159159
if (!filter.AgentIds.IsNullOrEmpty())
@@ -174,13 +174,13 @@ public PagedItems<InstructionLogModel> GetInstructionLogs(InstructLogFilter filt
174174
}
175175

176176
var filterDef = builder.And(filters);
177-
var sortDef = Builders<InstructionLogBetaDocument>.Sort.Descending(x => x.CreatedTime);
177+
var sortDef = Builders<InstructionLogDocument>.Sort.Descending(x => x.CreatedTime);
178178
var docs = _dc.InstructionLogs.Find(filterDef).Sort(sortDef).Skip(filter.Offset).Limit(filter.Size).ToList();
179179
var count = _dc.InstructionLogs.CountDocuments(filterDef);
180180

181181
var logs = docs.Select(x =>
182182
{
183-
var log = InstructionLogBetaDocument.ToDomainModel(x);
183+
var log = InstructionLogDocument.ToDomainModel(x);
184184
log.States = x.States.ToDictionary(p => p.Key, p =>
185185
{
186186
var jsonStr = p.Value.ToJson();

0 commit comments

Comments
 (0)