feat: update backlog sync logic to queue requests and adjust response structure

This commit is contained in:
MythEclipse
2026-05-15 18:53:12 +07:00
parent 61b07e4b01
commit 73901231c3
3 changed files with 26 additions and 15 deletions

View File

@@ -126,13 +126,13 @@
el.channelFilter.value = state.selectedTextChannel; el.channelFilter.value = state.selectedTextChannel;
applyActiveTab(state.activeTab); applyActiveTab(state.activeTab);
if ((textChanged || textGuildChanged) && state.selectedTextChannel && state.selectedTextGuild) { if ((textChanged || textGuildChanged) && state.selectedTextChannel && state.selectedTextGuild) {
await apiRequest('/api/backlog-sync', { apiRequest('/api/backlog-sync', {
method: 'POST', method: 'POST',
body: JSON.stringify({ guildId: state.selectedTextGuild, channelId: state.selectedTextChannel }), body: JSON.stringify({ guildId: state.selectedTextGuild, channelId: state.selectedTextChannel }),
}).catch((error) => showError(`Backlog sync failed: ${error.message}`)); }).catch((error) => showError(`Backlog sync failed: ${error.message}`));
} }
if (textChanged || textGuildChanged || state.activeTab === 'text') { if (textChanged || textGuildChanged || state.activeTab === 'text') {
await fetchText().catch((error) => showError(error.message)); fetchText().catch((error) => showError(error.message));
} }
await reconcileListenState(); await reconcileListenState();
await reconcileStreamingState(); await reconcileStreamingState();

View File

@@ -50,28 +50,37 @@ export function createSyncRoutes(client: Client): Router {
success: true, success: true,
channelId, channelId,
messagesSync: 0, messagesSync: 0,
queued: false,
skipped: true, skipped: true,
}); });
return; return;
} }
logger.info({ guildId, channelId }, "Starting backlog sync"); logger.info({ guildId, channelId }, "Queueing backlog sync");
const count = await syncSelectedChannelBacklog( syncSelectedChannelBacklog(client, guildId, channelId)
client, .then((count) => {
guildId, logger.info(
channelId, { guildId, channelId, messagesSync: count },
); "Backlog sync complete",
);
logger.info( })
{ guildId, channelId, messagesSync: count }, .catch((error) => {
"Backlog sync complete", logger.warn(
); {
guildId,
channelId,
error: error instanceof Error ? error.message : String(error),
},
"Backlog sync failed",
);
});
res.json({ res.json({
success: true, success: true,
channelId, channelId,
messagesSync: count, messagesSync: 0,
queued: true,
skipped: false, skipped: false,
}); });
} catch (error) { } catch (error) {

View File

@@ -45,7 +45,8 @@ describe("createSyncRoutes", () => {
expect(json).toHaveBeenCalledWith({ expect(json).toHaveBeenCalledWith({
success: true, success: true,
channelId: "selected-channel", channelId: "selected-channel",
messagesSync: 3, messagesSync: 0,
queued: true,
skipped: false, skipped: false,
}); });
expect(next).not.toHaveBeenCalled(); expect(next).not.toHaveBeenCalled();
@@ -91,6 +92,7 @@ describe("createSyncRoutes", () => {
success: true, success: true,
channelId: "selected-channel", channelId: "selected-channel",
messagesSync: 0, messagesSync: 0,
queued: false,
skipped: true, skipped: true,
}); });
}); });