corvix.storage¶
Local persistence for polled notifications.
The JSON cache uses fcntl advisory locks and is therefore supported on
Linux/POSIX platforms only.
Attributes¶
Classes¶
Protocol for notification persistence backends. |
|
Read/write notification snapshots to a JSON file. |
|
PostgreSQL-backed notification persistence implementing StorageBackend. |
Functions¶
|
Best-effort fsync of a directory after atomic replacement. |
|
|
|
|
|
|
|
|
|
|
|
|
|
Module Contents¶
- class corvix.storage.StorageBackend[source][source]¶
Bases:
ProtocolProtocol for notification persistence backends.
- save_records(user_id: corvix.types.UserId, records: list[corvix.domain.NotificationRecord], generated_at: datetime.datetime) None[source][source]¶
- load_records(user_id: corvix.types.UserId) tuple[datetime.datetime | None, list[corvix.domain.NotificationRecord]][source][source]¶
- dismiss_record(user_id: corvix.types.UserId, thread_id: str, account_id: str = 'primary') None[source][source]¶
- class corvix.storage.NotificationCache[source][source]¶
Read/write notification snapshots to a JSON file.
Implements StorageBackend using a single-user JSON file. The user_id parameter in protocol methods is ignored — the file is shared.
- save(records: list[corvix.domain.NotificationRecord], generated_at: datetime.datetime | None = None) None[source][source]¶
Persist records to disk.
- load() tuple[datetime.datetime | None, list[corvix.domain.NotificationRecord]][source][source]¶
Load snapshot from disk if available.
- _load_unlocked() tuple[datetime.datetime | None, list[corvix.domain.NotificationRecord]][source][source]¶
Load snapshot from disk without acquiring a file lock.
- _save_unlocked(records: list[corvix.domain.NotificationRecord], generated_at: datetime.datetime) None[source][source]¶
- _exclusive_lock() collections.abc.Iterator[None][source][source]¶
- save_records(user_id: corvix.types.UserId, records: list[corvix.domain.NotificationRecord], generated_at: datetime.datetime) None[source][source]¶
Save records; user_id ignored in single-user mode.
- load_records(user_id: corvix.types.UserId) tuple[datetime.datetime | None, list[corvix.domain.NotificationRecord]][source][source]¶
Load records; user_id ignored in single-user mode.
- dismiss_record(user_id: corvix.types.UserId, thread_id: str, account_id: str = 'primary') None[source][source]¶
Mark a record as dismissed by account/thread id in the JSON file.
- mark_record_read(user_id: corvix.types.UserId, thread_id: str, account_id: str = 'primary') None[source][source]¶
Mark a record as read by account/thread id in the JSON file.
- class corvix.storage.PostgresStorage[source][source]¶
PostgreSQL-backed notification persistence implementing StorageBackend.
Uses psycopg (sync) so it is safe to use from CLI commands and the synchronous Litestar route handlers (sync_to_thread=False is not used with this backend — callers should run in a thread pool if needed).
- save_records(user_id: corvix.types.UserId, records: list[corvix.domain.NotificationRecord], generated_at: datetime.datetime) None[source][source]¶
Upsert records for user_id. Preserves dismissed flag on conflict.
- load_records(user_id: corvix.types.UserId) tuple[datetime.datetime | None, list[corvix.domain.NotificationRecord]][source][source]¶
Load all records for user_id ordered by snapshot_at descending.
- dismiss_record(user_id: corvix.types.UserId, thread_id: str, account_id: str = 'primary') None[source][source]¶
Set dismissed=true for a specific account/thread id.
- mark_record_read(user_id: corvix.types.UserId, thread_id: str, account_id: str = 'primary') None[source][source]¶
Set unread=false for a specific account/thread id.
- corvix.storage._fsync_directory(path: pathlib.Path) None[source][source]¶
Best-effort fsync of a directory after atomic replacement.