Split MAX bot loops and make chats cache-first
This commit is contained in:
@@ -59,7 +59,12 @@ public sealed class ChatsController(
|
||||
}
|
||||
|
||||
[HttpGet("{chatId:guid}/messages")]
|
||||
public async Task<ActionResult<IReadOnlyList<MessageDto>>> GetMessages(Guid chatId, int take = 80, DateTimeOffset? before = null, CancellationToken cancellationToken = default)
|
||||
public async Task<ActionResult<IReadOnlyList<MessageDto>>> GetMessages(
|
||||
Guid chatId,
|
||||
int take = 80,
|
||||
DateTimeOffset? before = null,
|
||||
bool sync = false,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var chat = await db.Chats.FirstOrDefaultAsync(x => x.Id == chatId && x.DeletedAt == null, cancellationToken);
|
||||
if (chat is null)
|
||||
@@ -67,7 +72,7 @@ public sealed class ChatsController(
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if (before is null && !string.IsNullOrWhiteSpace(chat.ExternalId))
|
||||
if (sync && before is null && !string.IsNullOrWhiteSpace(chat.ExternalId))
|
||||
{
|
||||
await syncService.SyncChatHistoryAsync(chat.ExternalId, chat.WebUrl, cancellationToken);
|
||||
db.ChangeTracker.Clear();
|
||||
|
||||
Reference in New Issue
Block a user