This commit is contained in:
Andras Schmelczer 2026-04-25 21:59:32 +01:00
parent a5b3cc5f3a
commit d23750f15b
6 changed files with 90 additions and 17 deletions

View file

@ -24,14 +24,18 @@ export async function scheduleOfflineChanges(
}) => void,
enqueueDelete: (path: RelativePath) => void
): Promise<void> {
const allLocalFiles = await operations.listFilesRecursively();
logger.info(`Scheduling sync for ${allLocalFiles.length} local files`);
const allLocalFiles = new Set(await operations.listFilesRecursively());
logger.info(`Scheduling sync for ${allLocalFiles.size} local files`);
const allDocuments = queue.allSettledDocuments();
// A doc is "possibly deleted" only if it has no local file. Including
// docs that still exist locally would queue a spurious delete alongside
// the update below.
const locallyPossiblyDeletedFiles: DocumentWithPath[] = [];
for (const [path, record] of allDocuments.entries()) {
locallyPossiblyDeletedFiles.push({ path, record });
if (!allLocalFiles.has(path)) {
locallyPossiblyDeletedFiles.push({ path, record });
}
}
const locallyPossibleCreatedFiles: RelativePath[] = [];

View file

@ -154,6 +154,17 @@ export class Syncer {
public reset(): void {
this.queue.clearPending();
this.clearOfflineScanGate();
}
/**
* Reset the "have we already scanned this session" gate so a later
* `scheduleSyncForOfflineChanges()` actually performs a fresh scan
* instead of returning the previous (resolved) promise. Called when
* sync is paused so the next start picks up any offline edits made
* while sync was off.
*/
public clearOfflineScanGate(): void {
const current = this.runningScheduleSyncForOfflineChanges;
if (current !== undefined) {
void current.finally(() => {