feat: update backlog sync logic to queue requests and adjust response structure
This commit is contained in:
+2
-2
@@ -126,13 +126,13 @@
|
||||
el.channelFilter.value = state.selectedTextChannel;
|
||||
applyActiveTab(state.activeTab);
|
||||
if ((textChanged || textGuildChanged) && state.selectedTextChannel && state.selectedTextGuild) {
|
||||
await apiRequest('/api/backlog-sync', {
|
||||
apiRequest('/api/backlog-sync', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ guildId: state.selectedTextGuild, channelId: state.selectedTextChannel }),
|
||||
}).catch((error) => showError(`Backlog sync failed: ${error.message}`));
|
||||
}
|
||||
if (textChanged || textGuildChanged || state.activeTab === 'text') {
|
||||
await fetchText().catch((error) => showError(error.message));
|
||||
fetchText().catch((error) => showError(error.message));
|
||||
}
|
||||
await reconcileListenState();
|
||||
await reconcileStreamingState();
|
||||
|
||||
@@ -50,28 +50,37 @@ export function createSyncRoutes(client: Client): Router {
|
||||
success: true,
|
||||
channelId,
|
||||
messagesSync: 0,
|
||||
queued: false,
|
||||
skipped: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info({ guildId, channelId }, "Starting backlog sync");
|
||||
|
||||
const count = await syncSelectedChannelBacklog(
|
||||
client,
|
||||
guildId,
|
||||
channelId,
|
||||
);
|
||||
logger.info({ guildId, channelId }, "Queueing backlog sync");
|
||||
|
||||
syncSelectedChannelBacklog(client, guildId, channelId)
|
||||
.then((count) => {
|
||||
logger.info(
|
||||
{ guildId, channelId, messagesSync: count },
|
||||
"Backlog sync complete",
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.warn(
|
||||
{
|
||||
guildId,
|
||||
channelId,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
},
|
||||
"Backlog sync failed",
|
||||
);
|
||||
});
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
channelId,
|
||||
messagesSync: count,
|
||||
messagesSync: 0,
|
||||
queued: true,
|
||||
skipped: false,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -45,7 +45,8 @@ describe("createSyncRoutes", () => {
|
||||
expect(json).toHaveBeenCalledWith({
|
||||
success: true,
|
||||
channelId: "selected-channel",
|
||||
messagesSync: 3,
|
||||
messagesSync: 0,
|
||||
queued: true,
|
||||
skipped: false,
|
||||
});
|
||||
expect(next).not.toHaveBeenCalled();
|
||||
@@ -91,6 +92,7 @@ describe("createSyncRoutes", () => {
|
||||
success: true,
|
||||
channelId: "selected-channel",
|
||||
messagesSync: 0,
|
||||
queued: false,
|
||||
skipped: true,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user