feat: add file size tracking and sync interval settings to Obsidian plugin for improved reconciliation and performance

This commit is contained in:
Anish Sarkar 2026-04-20 23:48:51 +05:30
parent 28d3c628f1
commit 4d3406341d
7 changed files with 225 additions and 43 deletions

View file

@ -39,6 +39,11 @@ class NotePayload(_PluginBase):
aliases: list[str] = Field(default_factory=list)
content_hash: str = Field(..., description="Plugin-computed SHA-256 of the raw content")
size: int | None = Field(
default=None,
ge=0,
description="Byte size of the local file (mtime+size short-circuit signal). Optional for forward compatibility.",
)
mtime: datetime
ctime: datetime
@ -68,6 +73,10 @@ class DeleteBatchRequest(_PluginBase):
class ManifestEntry(_PluginBase):
hash: str
mtime: datetime
size: int | None = Field(
default=None,
description="Byte size last seen by the server. Enables mtime+size short-circuit; absent when not yet recorded.",
)
class ManifestResponse(_PluginBase):

View file

@ -15,9 +15,9 @@ Responsibilities:
- ``delete_note`` soft delete with a tombstone in ``document_metadata``
so reconciliation can distinguish "user explicitly killed this in the UI"
from "plugin hasn't synced yet".
- ``get_manifest`` return ``{path: {hash, mtime}}`` for every non-deleted
note belonging to a vault, used by the plugin's reconcile pass on
``onload``.
- ``get_manifest`` return ``{path: {hash, mtime, size}}`` for every
non-deleted note belonging to a vault, used by the plugin's reconcile
pass on ``onload``.
Design notes
------------
@ -108,6 +108,7 @@ def _build_metadata(
"embeds": payload.embeds,
"aliases": payload.aliases,
"plugin_content_hash": payload.content_hash,
"plugin_file_size": payload.size,
"mtime": payload.mtime.isoformat(),
"ctime": payload.ctime.isoformat(),
"connector_id": connector_id,
@ -360,8 +361,8 @@ async def get_manifest(
connector: SearchSourceConnector,
vault_id: str,
) -> ManifestResponse:
"""Return ``{path: {hash, mtime}}`` for every non-deleted note in this
vault.
"""Return ``{path: {hash, mtime, size}}`` for every non-deleted note in
this vault.
The plugin compares this against its local vault on every ``onload`` to
catch up edits made while offline. Rows missing ``plugin_content_hash``
@ -395,6 +396,8 @@ async def get_manifest(
mtime = datetime.fromisoformat(mtime_raw)
except ValueError:
continue
items[path] = ManifestEntry(hash=plugin_hash, mtime=mtime)
size_raw = meta.get("plugin_file_size")
size = int(size_raw) if isinstance(size_raw, int) else None
items[path] = ManifestEntry(hash=plugin_hash, mtime=mtime, size=size)
return ManifestResponse(vault_id=vault_id, items=items)