Lightning.Collaboration.PersistenceWriter (Lightning v2.14.5-pre1)

View Source

A GenServer that accumulates Yjs document updates and batches them for efficient database writes.

This process handles the batched persistence strategy using debouncing, size limits, and time limits to determine optimal flush timing. It monitors the SharedDoc process for proper cleanup and lifecycle management.

The writer uses several strategies for efficient persistence:

  • Debouncing: Waits for activity to settle before saving
  • Batching: Combines multiple updates into a single database write
  • Checkpointing: Periodically consolidates updates for faster loading
  • Cleanup: Removes old updates after checkpoints

Summary

Functions

Adds a Yjs update to the pending batch for persistence.

Returns a specification to start this module under a supervisor.

Flushes all pending updates and stops the writer.

Starts the PersistenceWriter GenServer for a specific document.

Functions

add_update(document_name, update)

Adds a Yjs update to the pending batch for persistence.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

flush_and_stop(document_name)

Flushes all pending updates and stops the writer.

This is called when the document is being unbound and ensures all updates are persisted before cleanup.

start_link(opts)

@spec start_link(opts :: Keyword.t()) :: GenServer.on_start()

Starts the PersistenceWriter GenServer for a specific document.

Registers the process in the Registry with key {:persistence_writer, document_name}.