Split MAX bot loops and make chats cache-first

This commit is contained in:
sevenhill
2026-07-05 23:20:20 +03:00
parent 0106130744
commit 3bc6456ed7
7 changed files with 157 additions and 16 deletions
@@ -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();