MCPcopy Index your code
hub / github.com/ZenNotes/zennotes / scheduleDatabaseWrite

Function scheduleDatabaseWrite

packages/app-core/src/store.ts:2535–2562  ·  view source on GitHub ↗
(
  csvPath: string,
  kind: 'rows' | 'schema',
  getDoc: () => DatabaseDoc | undefined
)

Source from the content-addressed store, hash-verified

2533}
2534
2535function scheduleDatabaseWrite(
2536 csvPath: string,
2537 kind: 'rows' | 'schema',
2538 getDoc: () => DatabaseDoc | undefined
2539): void {
2540 const prev = databaseWriteKind.get(csvPath)
2541 databaseWriteKind.set(csvPath, kind === 'schema' || prev === 'schema' ? 'schema' : 'rows')
2542 const existing = databaseSaveTimers.get(csvPath)
2543 if (existing) clearTimeout(existing)
2544 databaseSaveTimers.set(
2545 csvPath,
2546 setTimeout(() => {
2547 databaseSaveTimers.delete(csvPath)
2548 const writeKind = databaseWriteKind.get(csvPath) ?? 'rows'
2549 databaseWriteKind.delete(csvPath)
2550 const doc = getDoc()
2551 if (!doc) return
2552 const done = (): void => {
2553 lastDatabaseWriteAt.set(csvPath, Date.now())
2554 }
2555 const write =
2556 writeKind === 'schema'
2557 ? window.zen.writeDatabaseSchema(csvPath, databaseToSidecar(doc), doc.rows)
2558 : window.zen.writeDatabaseRows(csvPath, doc.rows)
2559 void write.catch((err) => console.error('database write failed', err)).finally(done)
2560 }, DATABASE_SAVE_DEBOUNCE_MS)
2561 )
2562}
2563
2564/**
2565 * The database table is the source of truth for a record's properties; the

Callers 1

store.tsFile · 0.85

Calls 4

databaseToSidecarFunction · 0.85
deleteMethod · 0.80
writeDatabaseSchemaMethod · 0.80
writeDatabaseRowsMethod · 0.80

Tested by

no test coverage detected