Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

A handle to the rq database.

Implementations§

Source§

impl Store

Source

pub fn open(path: &Path) -> Result<Store>

Open (creating if needed) the database at path, enabling WAL and applying the schema.

Source

pub fn open_in_memory() -> Result<Store>

Open an in-memory database — used by tests.

Examples found in repository?
examples/bench.rs (line 32)
29fn main() {
30    let root = PathBuf::from(std::env::args().nth(1).unwrap_or_else(|| ".".into()));
31
32    let mut store = Store::open_in_memory().expect("open store");
33    let stats = index::index_path(&mut store, &root).expect("index");
34    println!(
35        "indexed {} symbols from {} file(s) under {}",
36        stats.symbols,
37        stats.files_indexed,
38        root.display()
39    );
40
41    // warm up
42    for q in QUERIES {
43        let _ = search::search(&store, q, None, None, &search::ActiveFiles::default(), 10);
44    }
45
46    let mut times_us: Vec<u128> = Vec::new();
47    for _ in 0..200 {
48        for q in QUERIES {
49            let start = Instant::now();
50            let _ = search::search(&store, q, None, None, &search::ActiveFiles::default(), 10)
51                .expect("search");
52            times_us.push(start.elapsed().as_micros());
53        }
54    }
55    times_us.sort_unstable();
56
57    let pct = |p: f64| times_us[((times_us.len() as f64 - 1.0) * p).round() as usize];
58    println!(
59        "search over {} runs: p50 {} µs   p95 {} µs   max {} µs",
60        times_us.len(),
61        pct(0.50),
62        pct(0.95),
63        times_us[times_us.len() - 1],
64    );
65    let budget_us = 50_000;
66    let over = times_us.iter().filter(|&&t| t > budget_us).count();
67    println!("{}/{} runs exceeded the 50 ms budget", over, times_us.len());
68}
Source

pub fn upsert_repository( &self, identity: &RepoIdentity, default_branch: Option<&str>, ) -> Result<i64>

Insert or update a repository, returning its id.

Source

pub fn upsert_checkout( &self, repository_id: i64, root_path: &str, branch: Option<&str>, ) -> Result<()>

Record (or update) a local checkout of a repository.

Source

pub fn file_unchanged( &self, repository_id: i64, path: &str, content_hash: &str, ) -> Result<bool>

True if path is already indexed at this exact content hash — the incremental-skip check.

Source

pub fn file_mtimes( &self, repository_id: i64, ) -> Result<HashMap<String, Option<i64>>>

Indexed path → stored mtime for a repository. The budgeted warm pass uses this to skip unchanged files with a cheap stat (no read or re-hash).

Source

pub fn replace_file_symbols( &mut self, repository_id: i64, path: &str, language: &str, mtime: Option<i64>, content_hash: &str, symbols: &[Symbol], ) -> Result<()>

Replace all symbols for one file — the single-file form of Store::replace_files (same upsert, hash-skip, and batching).

Source

pub fn replace_files( &mut self, repository_id: i64, files: &[FileSymbols], ) -> Result<(usize, usize)>

Write many parsed files, one transaction per chunk — a batched fsync instead of one per file, while bounding how much a single transaction holds (a cold index of a huge repo would otherwise be one enormous txn). A file whose content hash already matches the index is skipped (not rewritten). Returns (files_written, symbols_written); skips don’t count.

Source

pub fn defer_fts_insert(&self) -> Result<()>

Suspend per-row FTS maintenance for a cold bulk index: drop the AFTER INSERT trigger so symbol inserts skip the expensive per-row trigram tokenization. Pair with rebuild_fts, which rebuilds the index in one pass and restores the trigger. No-op safe to call when the trigger is already gone.

Source

pub fn rebuild_fts(&self) -> Result<()>

Rebuild the trigram FTS index from the symbols table in one bulk pass — far cheaper than the per-row trigger on a cold index — then recreate the AFTER INSERT trigger so later incremental writes stay in sync. The inverse of defer_fts_insert. One transaction: a concurrent writer either lands before the rebuild (and is captured by it — the rebuild scans the whole symbols table) or after the trigger is back, never in between.

Source

pub fn fts_trigger_missing(&self) -> Result<bool>

Whether the AFTER INSERT FTS-sync trigger is currently absent — true only mid-bulk-index (see defer_fts_insert) or after one crashed before its rebuild_fts.

Source

pub fn set_coverage( &self, repository_id: i64, files_seen: i64, files_indexed: i64, status: &str, ) -> Result<()>

Record indexing coverage for a repository (scope full).

Source

pub fn set_file_git_ts( &mut self, repository_id: i64, times: &HashMap<String, i64>, ) -> Result<()>

Set the last-commit time for files in a repository, from a path → unix-ts map (git log). Files not in the map are left untouched.

Source

pub fn coverage_overview(&self) -> Result<Vec<CoverageRow>>

All known repositories with their coverage status and current totals.

Source

pub fn identity_for_root(&self, root: &str) -> Result<Option<String>>

The normalized identity of a repository by one of its checkout roots, if known — lets the hot path resolve identity from the cache instead of forking git remote. root should be the canonical work-tree path.

Source

pub fn repository_id(&self, identity: &str) -> Result<Option<i64>>

The id of a repository by its normalized identity, if known.

Source

pub fn coverage_status(&self, identity: &str) -> Result<Option<String>>

Coverage status for a repository’s full scope (never/warming/ complete), or None if the repository is unknown.

Source

pub fn repo_totals(&self, repository_id: i64) -> Result<(i64, i64)>

Current indexed totals for a repository: (files, symbols).

Source

pub fn symbols_in_file( &self, repository_id: i64, path: &str, ) -> Result<Vec<SymbolRow>>

Every symbol defined in one file (repo-relative path), in line order — a structural outline rather than a ranked search. Backed by idx_symbols_file.

Source

pub fn checkout_root(&self, repository_id: i64) -> Result<Option<String>>

The on-disk root of a repository’s checkout, used to resolve relative paths when validating staleness.

Source

pub fn checkout_roots(&self, repository_id: i64) -> Result<Vec<String>>

Every checkout root recorded for a repository, newest first. A repo can have more than one (it was moved or cloned twice, both under the same remote identity), and an old row may be stale — so callers that read files try these in order (current checkout before a stale one).

Source

pub fn forget_checkout(&mut self, root_path: &str) -> Result<()>

Drop a checkout row — used to prune a stale binding (a repo moved away from root_path). Symbols/coverage are keyed by repo identity, not this row, so forgetting a checkout only forgets where the repo was on disk.

Source

pub fn forget_file(&mut self, repository_id: i64, path: &str) -> Result<()>

Drop a file and its symbols — used when a file has been deleted on disk.

Source

pub fn drop_repository(&mut self, repository_id: i64) -> Result<()>

Drop a repository entirely — the inverse of indexing it: its symbols (and their FTS rows, via trigger), files, coverage, learned selections, events, checkout, and the repository row. Deleted in FK-safe order in one transaction.

Source

pub fn record_event( &self, kind: &str, query: Option<&str>, repository_id: Option<i64>, path: Option<&str>, line: Option<i64>, branch: Option<&str>, ) -> Result<()>

Append a raw interaction event (the cheap write on the hot path; rollup happens later in Store::aggregate_events).

Source

pub fn selections_for(&self, query_norm: &str) -> Result<Vec<SelectionStat>>

Learned selections relevant to a query, read by ranking. Matches not just the exact query but any shorter query the user has selected for — a pick for han informs handler — so typing more keeps the benefit.

Source

pub fn aggregate_events(&mut self, batch: usize) -> Result<usize>

Roll up to batch new open/select events into selection_stats. Returns how many events were processed. Resolves the chosen symbol from (repo, path, line) at rollup time, turning a selection into a (query, file, name) signal. This is the amortized post-processing run after a user interaction.

Source

pub fn prune_events(&self, keep_recent: i64) -> Result<usize>

Keep the raw events log bounded. Deletes only events that have already been rolled up (id ≤ the aggregation high-water mark) and are not among the most recent keep_recent rows (which is_repeat_search needs). Returns the number deleted.

Source

pub fn indexed_head(&self, repository_id: i64) -> Result<Option<String>>

The git HEAD sha recorded at the last complete index of a repo, if any — used to detect that the committed tree is unchanged since indexing.

Source

pub fn set_indexed_head(&self, repository_id: i64, head: &str) -> Result<()>

Record the git HEAD sha at a complete index.

Source

pub fn git_ts_head(&self, repository_id: i64) -> Result<Option<String>>

The git HEAD sha at the last commit-times capture (recency signal), if any — lets the next capture read only the commits since, or skip the git log entirely when HEAD hasn’t moved.

Source

pub fn set_git_ts_head(&self, repository_id: i64, head: &str) -> Result<()>

Record the git HEAD sha a commit-times capture ran at.

Source

pub fn warm_lock(&self, identity: &str) -> Result<Option<(u32, i64)>>

The detached-warm single-flight lock for a repo: (pid, stamped_at) of the process that claimed it, if any. Liveness/staleness policy is the caller’s (the store just holds the record).

Source

pub fn set_warm_lock(&self, identity: &str, pid: u32) -> Result<()>

Claim the detached-warm lock for this process.

Source

pub fn clear_warm_lock(&self, identity: &str) -> Result<()>

Release the detached-warm lock.

Source

pub fn branch_files_get( &self, identity: &str, ) -> Result<Option<(String, i64, Vec<String>)>>

The cached branch-changed file list for a repo: (stamp, computed_at, files). Stored rather than recomputed because the git diff behind it is O(tracked files) and runs on the search path.

Source

pub fn branch_files_set( &self, identity: &str, stamp: &str, at: i64, files: &[String], ) -> Result<()>

Source

pub fn search_candidates( &self, query: &str, limit: usize, force_fuzzy: bool, ) -> Result<Vec<SymbolRow>>

Candidate symbols for a query, drawn from cheap layers and merged: exact/prefix on name_lower, then broad fuzzy recall (first-char anchor, trigram FTS, path). Ranking happens in crate::search; this only narrows the field.

When force_fuzzy is false and exact/prefix already matched, the broad fuzzy layers are skipped: the relevance gate drops every fuzzy candidate once a strong (exact/prefix) hit exists, so fetching and scoring them is wasted. A wildcard query passes force_fuzzy = true — it isn’t gated and always needs the trigram recall.

Trait Implementations§

Source§

impl Drop for Store

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl !Sync for Store

§

impl !UnwindSafe for Store

§

impl Send for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.