add readonly load state
This commit is contained in:
parent
ed729bf18d
commit
45fd30aaf8
|
|
@ -9,7 +9,7 @@ namespace BotSharp.Abstraction.Conversations;
|
|||
public interface IConversationStateService
|
||||
{
|
||||
string GetConversationId();
|
||||
Dictionary<string, string> Load(string conversationId);
|
||||
Dictionary<string, string> Load(string conversationId, bool isReadOnly = false);
|
||||
string GetState(string name, string defaultValue = "");
|
||||
bool ContainsState(string name);
|
||||
Dictionary<string, string> GetStates();
|
||||
|
|
|
|||
|
|
@ -117,9 +117,9 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
|||
return this;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> Load(string conversationId)
|
||||
public Dictionary<string, string> Load(string conversationId, bool isReadOnly = false)
|
||||
{
|
||||
_conversationId = conversationId;
|
||||
_conversationId = !isReadOnly ? conversationId : null;
|
||||
|
||||
var routingCtx = _services.GetRequiredService<IRoutingContext>();
|
||||
var curMsgId = routingCtx.MessageId;
|
||||
|
|
@ -320,7 +320,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
Save();
|
||||
|
||||
}
|
||||
|
||||
public bool ContainsState(string name)
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ public class ConversationController : ControllerBase
|
|||
var result = ConversationViewModel.FromSession(conversations.Items.First());
|
||||
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
result.States = state.Load(conversationId);
|
||||
result.States = state.Load(conversationId, isReadOnly: true);
|
||||
|
||||
var user = await userService.GetUser(result.User.Id);
|
||||
result.User = UserViewModel.FromUser(user);
|
||||
|
|
|
|||
|
|
@ -191,14 +191,11 @@ public partial class MongoRepository
|
|||
{
|
||||
if (string.IsNullOrEmpty(conversationId) || states == null) return;
|
||||
|
||||
var filterConv = Builders<ConversationDocument>.Filter.Eq(x => x.Id, conversationId);
|
||||
var filterStates = Builders<ConversationStateDocument>.Filter.Eq(x => x.ConversationId, conversationId);
|
||||
var saveStates = states.Select(x => StateMongoElement.ToMongoElement(x)).ToList();
|
||||
var updateStates = Builders<ConversationStateDocument>.Update.Set(x => x.States, saveStates);
|
||||
var updateConv = Builders<ConversationDocument>.Update.Set(x => x.UpdatedTime, DateTime.UtcNow);
|
||||
|
||||
_dc.ConversationStates.UpdateOne(filterStates, updateStates);
|
||||
_dc.Conversations.UpdateOne(filterConv, updateConv);
|
||||
}
|
||||
|
||||
public void UpdateConversationStatus(string conversationId, string status)
|
||||
|
|
@ -391,7 +388,7 @@ public partial class MongoRepository
|
|||
{
|
||||
var skip = (page - 1) * batchSize;
|
||||
var candidates = _dc.Conversations.AsQueryable()
|
||||
.Where(x => (x.DialogCount <= messageLimit) && x.UpdatedTime <= utcNow.AddHours(-bufferHours))
|
||||
.Where(x => x.DialogCount <= messageLimit && x.UpdatedTime <= utcNow.AddHours(-bufferHours))
|
||||
.Skip(skip)
|
||||
.Take(batchSize)
|
||||
.Select(x => x.Id)
|
||||
|
|
|
|||
Loading…
Reference in a new issue