Arcana.Graph.GraphStore.Ecto (Arcana v3.0.1)

Copy Markdown View Source

Ecto/PostgreSQL implementation of the GraphStore behaviour.

This is the default graph storage backend, storing entities, relationships, and mentions in PostgreSQL tables.

Summary

Functions

Deletes entities in the collection that have no remaining mentions.

Runs fun inside a transaction holding the collection's advisory lock.

Functions

sweep_orphans(collection_id, opts)

Deletes entities in the collection that have no remaining mentions.

Runs under the collection's write lock (see with_write_lock/3) so it cannot delete an entity a concurrent build has inserted but not yet mentioned. Relationships cascade via FK; communities overlapping the deleted entities are marked dirty.

with_write_lock(collection_id, opts, fun)

Runs fun inside a transaction holding the collection's advisory lock.

Uses pg_advisory_xact_lock/1 keyed on the collection, the same idiom Arcana.Ingest uses for the replace swap. Both the entity/mention persist path and sweep_orphans/2 take it, so a sweep can never land between an entity insert and its mention insert.

Keep the wrapped work to DB writes: the lock blocks every concurrent graph write for the collection until the transaction commits.