s365b.core.catalog¶
Catalog writes: protected objects, item versions and sync state.
The catalog is the database record of what was backed up and when. Content
itself lives in the repository; versions store a
ContentRef pointing to it.
Versioning rules (see Catalog.record()):
A new item gets its first version.
A changed item closes its current version (
valid_to = now) and gets a new one.An unchanged item (same content, name, path and metadata) gets nothing, so re-reading the same data after a crash or a full resync costs no space.
A deleted item closes its current version and gets a deletion marker.
An item whose current version is in another repository gets a new version in this one, even if unchanged: after a job moves to a new repository, that repository alone holds every current item.
Sync state is saved with the repository it was saved for. A backup into
another repository starts from what
state_for_new_repository() keeps.
Classes¶
Counts of what |
|
Catalog operations within one database session. |
Functions¶
|
Store an object's current item count and newest item time on its row. |
Module Contents¶
- class s365b.core.catalog.VersionStats[source]¶
Counts of what
Catalog.record()did.- Variables:
new – Items seen for the first time.
changed – Items with a new version.
unchanged – Items that matched their current version.
deleted – Items marked deleted.
bytes – Plaintext bytes of content in new versions.
- add(other: VersionStats) None[source]¶
Add another set of counts to this one.
- Parameters:
other – Counts to add.
- class s365b.core.catalog.Catalog(session: sqlalchemy.ext.asyncio.AsyncSession)[source]¶
Catalog operations within one database session.
- Parameters:
session – Open session; the caller commits.
- async sync_objects(tenant_fk: int, module_id: str, objects: collections.abc.Iterable[s365b.modules.sdk.ProtectedObject], now: datetime.datetime) list[s365b.db.models.ProtectedObjectRow][source]¶
Upsert discovered objects and mark undiscovered ones as gone.
- Parameters:
tenant_fk – Tenant row ID.
module_id – Module that discovered the objects.
objects – Everything the module discovered this time.
now – Discovery time.
- Returns:
Rows for the discovered objects.
- async load_state(object_fk: int) s365b.modules.sdk.SyncState[source]¶
Return the last saved sync state of an object.
- Parameters:
object_fk – Protected object row ID.
- Returns:
The state; empty if never saved.
- async state_for(object_fk: int, repository_fk: int, module: s365b.modules.sdk.BackupModule) s365b.modules.sdk.SyncState[source]¶
Return the state a backup of an object into a repository starts from.
- Parameters:
object_fk – Protected object row ID.
repository_fk – Repository the backup writes to.
module – The object’s module.
- Returns:
The saved state; if it was saved for another repository, what the module keeps of it for a backup into a new one.
- async current_items(object_fk: int, field: str, value: str, repository_fk: int | None = None) dict[str, dict[str, Any]][source]¶
An object’s current, not deleted items with
meta[field] == value.- Parameters:
object_fk – Protected object row ID.
field – Metadata field, e.g.
"folder_id".value – Its value.
repository_fk – If given, items whose current version is in another repository come with empty metadata, so a module comparing change keys reads them again.
- Returns:
Their metadata, by item key.
- async state_version(object_fk: int) str | None[source]¶
Return the version of the module that last saved an object’s state.
- Parameters:
object_fk – Protected object row ID.
- Returns:
The module version;
Noneif never saved.
- async save_state(object_fk: int, state: s365b.modules.sdk.SyncState, module_version: str, repository_fk: int) None[source]¶
Save an object’s sync state.
- Parameters:
object_fk – Protected object row ID.
state – State to save.
module_version – Version of the module that produced it.
repository_fk – Repository the backup that produced it writes to.
- async apply_group(object_fk: int, change: s365b.modules.sdk.GroupChange, *, repository_fk: int, run_fk: int | None, now: datetime.datetime) tuple[VersionStats, list[s365b.modules.sdk.ItemVersion]][source]¶
Re-path or delete every current item of a group.
- Parameters:
object_fk – Protected object row ID.
change – The group change yielded by the module.
repository_fk – Repository of the new versions (content is reused, so this is the current version’s repository).
run_fk – Job run that produced it.
now – Commit time.
- Returns:
What changed, and the new versions (without content) for change tracking.
- async record(object_fk: int, version: s365b.modules.sdk.ItemVersion, content: s365b.storage.repository.ContentRef | None, *, repository_fk: int, run_fk: int | None, now: datetime.datetime) VersionStats[source]¶
Record one item version yielded by a module.
- Parameters:
object_fk – Protected object row ID.
version – The module’s item version.
content – Where its content was stored, if it has content.
repository_fk – Repository holding the content.
run_fk – Job run that produced it.
now – Commit time; becomes
valid_from/valid_to.
- Returns:
What changed (one counter is incremented).
- async s365b.core.catalog.refresh_summary(s: sqlalchemy.ext.asyncio.AsyncSession, object_fk: int) None[source]¶
Store an object’s current item count and newest item time on its row.
Browse lists thousands of mailboxes; counting their items on every page load would read the whole catalog, so the count is kept after each backup.