Skip to content

Commit 6df27b9

Browse files
committed
optimize yield config
1 parent b2b6cfc commit 6df27b9

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

apps/api/src/sync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
} from "./persistence.js";
1111
import type { SyncJobResult } from "./sync-queue.js";
1212

13-
const messagePersistenceYieldInterval = 100;
13+
const messagePersistenceYieldInterval = 10;
1414

1515
export type ImapMailbox = Omit<StoredMailbox, "systemRole"> & {
1616
specialUse?: string;

tests/message-sync.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,55 @@ describe("recent Message sync", () => {
331331
).toHaveLength(200);
332332
});
333333

334+
it("yields while persisting fewer than one hundred reconciliation messages", async () => {
335+
const persistence = createHybridPersistence();
336+
const account: ConfiguredMailAccount = {
337+
id: "personal",
338+
emailAddress: "me@example.com",
339+
appPassword: "personal-app-password",
340+
};
341+
const mailDatabase = persistence.mailDatabaseFor("personal");
342+
mailDatabase.saveMailbox({ id: "inbox", name: "Inbox", unreadCount: 99 });
343+
let syncFinished = false;
344+
let timerRanBeforeSyncFinished = false;
345+
const client: MessageSyncClient = {
346+
async listRecentMessages() {
347+
return Array.from({ length: 99 }, (_, index) => ({
348+
id: `message-${index}`,
349+
stableIdentity: `gmail:personal:message-${index}`,
350+
subject: "Medium sync Message",
351+
receivedAt: "2026-05-23T10:00:00.000Z",
352+
unread: true,
353+
readableBody: "<p>Hello</p>",
354+
attachments: [],
355+
mailboxIds: ["inbox"],
356+
}));
357+
},
358+
};
359+
360+
const syncPromise = syncRecentReconciliation({
361+
accounts: [account],
362+
persistence,
363+
client,
364+
now: new Date("2026-05-24T12:00:00.000Z"),
365+
windowDays: 7,
366+
}).finally(() => {
367+
syncFinished = true;
368+
});
369+
await new Promise<void>((resolve) =>
370+
setTimeout(() => {
371+
timerRanBeforeSyncFinished = !syncFinished;
372+
resolve();
373+
}, 0),
374+
);
375+
await syncPromise;
376+
377+
expect(timerRanBeforeSyncFinished).toBe(true);
378+
expect(
379+
mailDatabase.listMessagesForMailbox("personal", "inbox", { limit: 99 }).messages,
380+
).toHaveLength(99);
381+
});
382+
334383
it("uses saved Mailbox checkpoints for incremental Message sync", async () => {
335384
const persistence = createHybridPersistence();
336385
const account: ConfiguredMailAccount = {

0 commit comments

Comments
 (0)