pub struct Index { /* private fields */ }Expand description
SQLite-backed cache index.
Wraps a single Connection. All public methods in this module treat index
errors as non-fatal: they warn to stderr and fall back gracefully, matching
the tolerant pattern used in inventory.rs.
Implementations§
Source§impl Index
impl Index
Sourcepub fn open(base: &Path) -> Self
pub fn open(base: &Path) -> Self
Opens (or creates) the index at <base>/index.db.
Behaviour on failure at any stage (open, WAL pragma, migration, integrity check):
- Print
warning: …to stderr. - Delete
index.db,index.db-wal,index.db-shmfrombase. - Attempt to create a fresh db in the same location.
- If that also fails, fall back to an in-memory db so the command continues without an index — never panic, never abort.
Sourcepub fn open_in_memory() -> Self
pub fn open_in_memory() -> Self
Opens an in-memory index for tests (same migration, no disk I/O).
Sourcepub fn cached_common_dir(&self, path: &Path) -> Option<(String, PathBuf)>
pub fn cached_common_dir(&self, path: &Path) -> Option<(String, PathBuf)>
Returns (common_dir_hash, common_dir) cached for path, or None on
miss or any index error.
Sourcepub fn put_repo_common_dir(
&self,
path: &Path,
common_dir_hash: &str,
common_dir: &Path,
)
pub fn put_repo_common_dir( &self, path: &Path, common_dir_hash: &str, common_dir: &Path, )
Upserts (path, common_dir_hash, common_dir) into repos, leaving
the remaining columns (default_branch, default_sha, refs_fingerprint,
last_indexed) NULL. On any index error, prints a warning and continues.
Sourcepub fn cached_loops(
&self,
hash: &str,
refs_fp: i64,
default_sha: &str,
) -> Option<Vec<LoopRow>>
pub fn cached_loops( &self, hash: &str, refs_fp: i64, default_sha: &str, ) -> Option<Vec<LoopRow>>
Returns the cached loops for hash, but ONLY when the stored repo row
proves the cache is still valid:
repos.refs_fingerprint == refs_fp(refs haven’t changed), ANDrepos.default_sha == default_sha(the base hasn’t moved).
Returns None on any mismatch, on a missing/un-populated repo row, or on
any index error. A NULL default_sha / refs_fingerprint (a repo row
inserted by put_repo_common_dir but never put_loops’d) is a clean
miss — no warning is emitted, since it is the normal pre-put_loops state.
Sourcepub fn put_loops(
&self,
hash: &str,
path: &Path,
common_dir: &Path,
default_branch: &str,
default_sha: &str,
refs_fp: i64,
rows: &[LoopRow],
)
pub fn put_loops( &self, hash: &str, path: &Path, common_dir: &Path, default_branch: &str, default_sha: &str, refs_fp: i64, rows: &[LoopRow], )
Write-through for a completed scan of one repo: upserts the repos row
(default branch/SHA, refs fingerprint, last_indexed) and REPLACES the
repo’s loops rows — all in a single transaction.
On any index error, prints a warning and continues (git is the source of truth; the index is disposable).
Sourcepub fn upsert_session(
&self,
path: &Path,
repo_path: &Path,
mtime: i64,
size: i64,
text: &str,
)
pub fn upsert_session( &self, path: &Path, repo_path: &Path, mtime: i64, size: i64, text: &str, )
Upserts a session’s bounded tail text into the sessions table and the
sessions_fts virtual table.
Reindexes ONLY when the stored (mtime, size) for path differs from
the supplied values. Unchanged files are skipped (no I/O, no FTS write).
size is compared alongside mtime so a same-second append that grows
the file still forces a reindex (closes the same-second FTS staleness
window, I-2). On any index error, prints a warning and continues.
Sourcepub fn session_mentions(
&self,
repo_path: &Path,
branch: &str,
) -> HashSet<PathBuf>
pub fn session_mentions( &self, repo_path: &Path, branch: &str, ) -> HashSet<PathBuf>
Returns the set of session file paths (scoped to repo_path) whose
indexed text matches branch via FTS5.
No file reads. On any index error, returns an empty set.
Sourcepub fn prune_missing_repos(&self)
pub fn prune_missing_repos(&self)
Deletes repos rows (and their dependent loops rows) whose repo is gone
from disk. This is stricter than inventory::prune_orphans, which
prunes on a single repo_path existence check (and also reclaims
unreadable files); here a row is removed only when BOTH the scanned path
AND the common_dir are gone.
A repo is an orphan only when BOTH its scanned path and its common_dir
no longer exist: a worktree directory may be removed while the shared bare
store under common_dir survives (its branches are still real), so we must
keep the row in that case. Removal is self-healing — a returning repo is
simply re-discovered and re-indexed on the next scan.
On any index error, prints a warning and continues (git is the source of truth; the index is disposable).