pub struct Cache { /* private fields */ }Expand description
Cache holds the store and the state of this run’s sync.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn record_edges(&self, source: &RepoPath, edges: Vec<RawEdge>)
pub fn record_edges(&self, source: &RepoPath, edges: Vec<RawEdge>)
record_edges holds the edges that one document declares until the
commit writes them (CACHE-1_AC-11).
Source§impl Cache
impl Cache
Sourcepub fn set_hint(&self, paths: Vec<RepoPath>)
pub fn set_hint(&self, paths: Vec<RepoPath>)
set_hint records the paths that a caller knows changed, so that the
next sync reads the file metadata of only those paths.
Sourcepub fn drop_hint(&self)
pub fn drop_hint(&self)
drop_hint forgets the paths that a caller said changed, so that the
next sync walks the repository.
Sourcepub fn note_missing(&self)
pub fn note_missing(&self)
note_missing records that the run read a file that the walk lists
and found it removed. In a run with a hint on a filled store, the
hint left that removal out (CACHE-1_AC-53).
Sourcepub fn missed(&self) -> bool
pub fn missed(&self) -> bool
missed returns whether this run’s hint left out a removed file
that the run read.
Sourcepub fn hint(&self) -> Option<Vec<RepoPath>>
pub fn hint(&self) -> Option<Vec<RepoPath>>
hint returns the paths that a caller said changed, or None when
the caller gave none.
Sourcepub fn tree_from_store(
&self,
root: &RepoRoot,
config: &Config,
changed: &[RepoPath],
) -> Result<Tree>
pub fn tree_from_store( &self, root: &RepoRoot, config: &Config, changed: &[RepoPath], ) -> Result<Tree>
tree_from_store builds the tree that a run with a hint works on. It
starts from the store’s files and directories. It drops what the
store recorded at or under each hinted path, and lists those paths
again as the walk lists them. It adds each directory above a hinted
path that the walk lists, up to its root. It removes each directory
above a hinted path that is no longer a directory. When no check has
filled the store, it walks the repository instead.
Source§impl Cache
impl Cache
Sourcepub fn outside_to_read(&self) -> Vec<RepoPath>
pub fn outside_to_read(&self) -> Vec<RepoPath>
outside_to_read returns the files outside the knowledge roots that
this run must read for markers. A file is one of them when:
- it is new
- its stat changed
- its modification time is so close to the last sync that a change might not show in the stat
Sourcepub fn unread(&self, path: &RepoPath)
pub fn unread(&self, path: &RepoPath)
unread records a file that the scan could not read. The store keeps
the file’s old row, so that the next run reads the file again, for
example when its permissions change and its stat does not.
Sourcepub fn record_markers(&self, path: &RepoPath, rows: Vec<MarkerRow>)
pub fn record_markers(&self, path: &RepoPath, rows: Vec<MarkerRow>)
record_markers records the markers that a scan of path found. The
commit writes them in place of the rows that the store holds for the
file.
Sourcepub fn stored_markers(&self, path: &RepoPath) -> Vec<MarkerRow>
pub fn stored_markers(&self, path: &RepoPath) -> Vec<MarkerRow>
stored_markers returns the markers of path that the store keeps,
in line order.
Sourcepub fn has_markers(&self, path: &RepoPath) -> bool
pub fn has_markers(&self, path: &RepoPath) -> bool
has_markers reports whether the store holds a row for any marker or
fault in path.
Source§impl Cache
impl Cache
Sourcepub fn identities_changed(&self, rows: Vec<IdentityRow>) -> bool
pub fn identities_changed(&self, rows: Vec<IdentityRow>) -> bool
identities_changed reports whether the current and former
identities of the knowledge stores differ from the ones that the
cache recorded. The commit writes the new rows (CACHE-1_AC-11).
Sourcepub fn formats_changed(
&self,
hash: u64,
fingerprint: impl FnOnce() -> Vec<(String, u64)>,
) -> Option<BTreeSet<String>>
pub fn formats_changed( &self, hash: u64, fingerprint: impl FnOnce() -> Vec<(String, u64)>, ) -> Option<BTreeSet<String>>
formats_changed returns the registry entries that an edit of the
formats file changed, or None when the file has the same hash as in
the last run. When the hash differs, fingerprint computes one hash for
each format and type of the current registry, and
formats_changed compares them with the formats rows of the cache.
The names whose hashes differ, and the names that were added or
removed, make up the returned set. The commit writes the new hash and
fingerprint (CACHE-1_AC-11).
Sourcepub fn schemas_changed(&self, rows: Vec<SchemaRow>) -> BTreeSet<(usize, String)>
pub fn schemas_changed(&self, rows: Vec<SchemaRow>) -> BTreeSet<(usize, String)>
schemas_changed returns, as (knowledge store, key) pairs, the
keys whose schema file differs from the cached one. A key’s schema
file is the file that claims the key. It differs when the schema
changed, was added or removed, or moved to another key. The commit
writes the new rows (CACHE-1_AC-11).
Sourcepub fn additional_changed(&self, rows: Vec<AdditionalRow>) -> BTreeSet<RepoPath>
pub fn additional_changed(&self, rows: Vec<AdditionalRow>) -> BTreeSet<RepoPath>
additional_changed returns the additional files whose governing
schema differs from the cached one: a glob started
or stopped matching the file, or another schema now governs it.
The commit writes the new rows (CACHE-1_AC-11).
Sourcepub fn readers_of(&self, queries: &BTreeSet<String>) -> BTreeSet<RepoPath>
pub fn readers_of(&self, queries: &BTreeSet<String>) -> BTreeSet<RepoPath>
readers_of returns every reader of any of queries, as the cache
recorded them. The queries table interns each query key and each
reader’s path, and the deps table pairs their ids.
Sourcepub fn history_queries(&self) -> BTreeSet<String>
pub fn history_queries(&self) -> BTreeSet<String>
history_queries returns the key of each query of the history
that a stored check read, one for each commit that HEAD named
(CACHE-1_AC-97).
Sourcepub fn record_output(&self, path: &RepoPath, findings: Vec<Finding>)
pub fn record_output(&self, path: &RepoPath, findings: Vec<Finding>)
record_output keeps the output of one check for the commit to
write.
Sourcepub fn record_deps(&self, path: &RepoPath, queries: &BTreeSet<Query>)
pub fn record_deps(&self, path: &RepoPath, queries: &BTreeSet<Query>)
record_deps keeps the queries that one check made for the commit
to write.
Sourcepub fn record_unsettled<'a>(&self, paths: impl Iterator<Item = &'a RepoPath>)
pub fn record_unsettled<'a>(&self, paths: impl Iterator<Item = &'a RepoPath>)
record_unsettled adds to the queries of each of paths, which the
run checked, the query that every run checks again, because each
holds a text that the formatter left unsettled (CACHE-2_AC-9).
Sourcepub fn record_citations(&self, source: &RepoPath, rows: Vec<CitationRow>)
pub fn record_citations(&self, source: &RepoPath, rows: Vec<CitationRow>)
record_citations keeps the citations that one document resolved
for the commit to write.
Sourcepub fn record_keys_of(&self, keys: &KeyIndex, checked: &BTreeSet<RepoPath>)
pub fn record_keys_of(&self, keys: &KeyIndex, checked: &BTreeSet<RepoPath>)
record_keys_of records the keys that each document in checked
declares in this run, and the anchors that the engine keeps in the
document. The commit writes them in place of the document’s rows in the
cache.
Sourcepub fn record_probe(&self, path: &RepoPath, on_disk: OnDisk)
pub fn record_probe(&self, path: &RepoPath, on_disk: OnDisk)
record_probe records what a path outside the walk names on disk,
nothing, a file, or a directory, so that the commit can write it. The
next sync checks the path with stat again.
Sourcepub fn record_assets(&self, rows: Vec<AssetRow>)
pub fn record_assets(&self, rows: Vec<AssetRow>)
record_assets keeps the asset pairings of this run for the commit
to write.
Sourcepub fn assets_changed(&self, rows: &[AssetRow]) -> BTreeSet<RepoPath>
pub fn assets_changed(&self, rows: &[AssetRow]) -> BTreeSet<RepoPath>
assets_changed returns the paths whose pairing differs from the
cached one. Such a path is an asset or a sidecar that gained, lost,
or changed its partner.
Sourcepub fn probes_changed(&self, root: &RepoRoot) -> BTreeSet<RepoPath>
pub fn probes_changed(&self, root: &RepoRoot) -> BTreeSet<RepoPath>
probes_changed returns the probed paths whose existence, or whose
kind, a file or a directory, changed after the cache recorded it.
Sourcepub fn stored_citations_of(
&self,
target: &RepoPath,
excluding: &BTreeSet<RepoPath>,
) -> Vec<Citation>
pub fn stored_citations_of( &self, target: &RepoPath, excluding: &BTreeSet<RepoPath>, ) -> Vec<Citation>
stored_citations_of returns the citations of target that the
cache holds, except those from removed files and from the sources in
excluding. This run resolves the citations of those sources again.
Sourcepub fn old_citation_targets(&self, source: &RepoPath) -> BTreeSet<RepoPath>
pub fn old_citation_targets(&self, source: &RepoPath) -> BTreeSet<RepoPath>
old_citation_targets returns the targets that source cited, as
the cache recorded them.
Sourcepub fn old_citations(&self, source: &RepoPath) -> BTreeSet<CitedFact>
pub fn old_citations(&self, source: &RepoPath) -> BTreeSet<CitedFact>
old_citations returns what source cited, as the cache recorded
it.
Source§impl Cache
impl Cache
Sourcepub fn record_plans_of(&self, plans: &PlanIndex, checked: &BTreeSet<RepoPath>)
pub fn record_plans_of(&self, plans: &PlanIndex, checked: &BTreeSet<RepoPath>)
record_plans_of keeps the paths that each document in checked
plans in this run. The commit writes them in place of the document’s
rows in the store.
Sourcepub fn old_plans_of(&self, path: &RepoPath) -> BTreeSet<Planned>
pub fn old_plans_of(&self, path: &RepoPath) -> BTreeSet<Planned>
old_plans_of returns the paths that the document at path planned,
as the store recorded them.
Sourcepub fn stored_plans(&self, except: &BTreeSet<RepoPath>) -> PlanIndex
pub fn stored_plans(&self, except: &BTreeSet<RepoPath>) -> PlanIndex
stored_plans returns the plans that the store records, except the
plans of the documents in except and of the removed files.
Source§impl Cache
impl Cache
Sourcepub fn record_row(&self, path: &RepoPath, row: DocRow)
pub fn record_row(&self, path: &RepoPath, row: DocRow)
record_row keeps the row of a document that this run read. The
commit writes the row when it differs from the store’s.
Sourcepub fn old_row(&self, path: &RepoPath) -> Option<DocRow>
pub fn old_row(&self, path: &RepoPath) -> Option<DocRow>
old_row returns the row that the store held for path before this
run.
Sourcepub fn stored_keys_for(
&self,
slugs: &BTreeSet<String>,
except: &BTreeSet<RepoPath>,
) -> KeyIndex
pub fn stored_keys_for( &self, slugs: &BTreeSet<String>, except: &BTreeSet<RepoPath>, ) -> KeyIndex
stored_keys_for returns the keys that the store holds for the given
slugs, from the documents that cite or capture them, and the anchors
with those slugs that the engine keeps. It leaves out the rows of the
documents that this run removed, and the rows of the documents in
except, whose keys this run captured.
Sourcepub fn old_keys_of(&self, path: &RepoPath) -> BTreeSet<(String, String, usize)>
pub fn old_keys_of(&self, path: &RepoPath) -> BTreeSet<(String, String, usize)>
old_keys_of returns the keys that the document at path declares,
as the cache recorded them, each as (scope, slug, knowledge).
Sourcepub fn old_anchors_of(&self, path: &RepoPath) -> BTreeSet<String>
pub fn old_anchors_of(&self, path: &RepoPath) -> BTreeSet<String>
old_anchors_of returns the slugs of the anchors that the engine
keeps in the document at path, as the cache recorded them.
Source§impl Cache
impl Cache
Sourcepub fn open(root: &RepoRoot, mode: CacheMode) -> Cache
pub fn open(root: &RepoRoot, mode: CacheMode) -> Cache
open opens the store under root, or opens it in memory for Off.
When the store file does not open, the run uses a store in memory. When
the store is of another version, format, or configuration, open
replaces it with an empty one. Neither case prints a message.
Source§impl Cache
impl Cache
Sourcepub fn sync(&self, tree: &Tree)
pub fn sync(&self, tree: &Tree)
sync compares the walk with the store to decide which files this
run must read (CACHE-1_AC-1, CACHE-1_AC-24). The sync treats a file
as unchanged, and doesn’t read it, when two conditions hold. Its
length and modification time equal those in the store. Its
modification time is earlier than the last sync by at least
RACY_MARGIN. The run reads any other file when a command needs it,
and the hash of the file decides whether it changed. The walk is
sorted by path, and the sync reads the rows of the store in the same
order. So one pass yields the unchanged, changed, added, and removed
files. The pass holds only the rows of the files that the run must
read. sync
also finds the directories that were added or removed.
Sourcepub fn dirs_changed(&self) -> (Vec<RepoPath>, Vec<RepoPath>)
pub fn dirs_changed(&self) -> (Vec<RepoPath>, Vec<RepoPath>)
dirs_changed returns the directories that the walk lists and the
store didn’t, and the directories that the store lists and the walk
no longer does.
Sourcepub fn must_read(&self, path: &RepoPath) -> bool
pub fn must_read(&self, path: &RepoPath) -> bool
must_read says whether a run must read path before it can trust
the hash in the store. The run must read the file when the file is
new, when its stat differs from the stat in the store, when its
modification time lies within RACY_MARGIN of the last sync, or
when the walk doesn’t list it.
Sourcepub fn observe(&self, path: &RepoPath, key: &FileKey) -> FileState
pub fn observe(&self, path: &RepoPath, key: &FileKey) -> FileState
observe records that the run read a file. The hash in key decides
whether the file changed, and the commit writes the row of the file.
Sourcepub fn knowledge_of(&self, path: &RepoPath) -> Option<usize>
pub fn knowledge_of(&self, path: &RepoPath) -> Option<usize>
knowledge_of returns the knowledge root that a walked file lies
under, if any.
Sourcepub fn hash_of(&self, path: &RepoPath) -> Option<u64>
pub fn hash_of(&self, path: &RepoPath) -> Option<u64>
hash_of returns the hash of a walked file: the hash that this run
read, the hash in the row of the store that the run holds, or, for a
file that the run didn’t read, the hash that hash_of reads from
the store.
Sourcepub fn is_document(&self, path: &RepoPath) -> bool
pub fn is_document(&self, path: &RepoPath) -> bool
is_document says whether the walk lists path as a document.
Sourcepub fn is_schema(&self, path: &RepoPath) -> bool
pub fn is_schema(&self, path: &RepoPath) -> bool
is_schema says whether the walk lists path as a schema document.
Sourcepub fn removed(&self) -> Vec<RepoPath>
pub fn removed(&self) -> Vec<RepoPath>
removed returns the files that the walk no longer lists.
Sourcepub fn is_new(&self, path: &RepoPath) -> bool
pub fn is_new(&self, path: &RepoPath) -> bool
is_new says whether the store had no row for path before this
run.
Sourcepub fn pending_candidates(&self) -> Vec<(RepoPath, bool)>
pub fn pending_candidates(&self) -> Vec<(RepoPath, bool)>
pending_candidates returns the candidate files that the walk lists.
The store doesn’t have their stat. Each is paired with a flag that
says whether the store has no row for it yet. The documents that
include or link such a file count as changed, although the run
doesn’t read the file (CACHE-1_AC-26). For a candidate that the run
read, such as an additional file, the hash decides instead whether
the file changed.
Sourcepub fn changed_set(&self) -> BTreeSet<RepoPath>
pub fn changed_set(&self) -> BTreeSet<RepoPath>
changed_set returns the files that this run read and found
changed, as a set.
Sourcepub fn changed(&self) -> Vec<RepoPath>
pub fn changed(&self) -> Vec<RepoPath>
changed returns the files that this run read and found changed, in
path order.
Sourcepub fn stats(&self) -> SyncStats
pub fn stats(&self) -> SyncStats
stats returns the counts of the sync of this run, and of its work
against the store.
Sourcepub fn commit(&self)
pub fn commit(&self)
commit writes the result of the run in one transaction: the rows
of every walked file and of the directories, the deletion of the
rows of the removed files, the rows, outputs, and markers that the
run produced, and the sync time. A failure is silent, and the next
run reads the files again (CACHE-1_AC-9).