Skip to main content

FileIRRepository

Trait FileIRRepository 

Source
pub trait FileIRRepository {
    // Required methods
    fn upsert(
        &self,
        branch_id: &BranchId,
        file: &ProjectFile,
        last_commit_date: Option<i64>,
    ) -> Result<(), StorageError>;
    fn upsert_with_symbol_index(
        &self,
        branch_id: &BranchId,
        file: &ProjectFile,
        last_commit_date: Option<i64>,
    ) -> Result<(), StorageError>;
    fn get_by_path(
        &self,
        branch_id: &BranchId,
        file_path: &str,
    ) -> Result<ProjectFile, StorageError>;
    fn get_by_branch(
        &self,
        branch_id: &BranchId,
    ) -> Result<Vec<ProjectFile>, StorageError>;
    fn get_file_hashes_by_branch(
        &self,
        branch_id: &BranchId,
    ) -> Result<HashMap<String, String>, StorageError>;
    fn delete_by_path(
        &self,
        branch_id: &BranchId,
        file_path: &str,
    ) -> Result<(), StorageError>;
    fn delete_with_symbol_index(
        &self,
        branch_id: &BranchId,
        file_path: &str,
    ) -> Result<(), StorageError>;
    fn check_content_hash(
        &self,
        branch_id: &BranchId,
        file_path: &str,
        content_hash: &str,
    ) -> Result<bool, StorageError>;
    fn get_file_dates_by_branch(
        &self,
        branch_id: &BranchId,
    ) -> Result<HashMap<String, Option<i64>>, StorageError>;
    fn update_convention_compliance_counts(
        &self,
        branch_id: &BranchId,
        counts: &HashMap<String, u32>,
    ) -> Result<(), StorageError>;
}
Expand description

Persistence operations for file IR records (parsed source file cache).

Required Methods§

Source

fn upsert( &self, branch_id: &BranchId, file: &ProjectFile, last_commit_date: Option<i64>, ) -> Result<(), StorageError>

Insert or update a file IR record. Uses (branch_id, file_path) as the natural key — if a row already exists, it is replaced.

last_commit_date is the Unix timestamp of the most recent git commit that touched this file (from collect_git_file_dates). None means the project is not a git repo or the file has no commit history.

Source

fn upsert_with_symbol_index( &self, branch_id: &BranchId, file: &ProjectFile, last_commit_date: Option<i64>, ) -> Result<(), StorageError>

Insert or update a file IR record and replace the matching symbol_definitions / symbol_imports rows in a single transaction.

Either every write commits, or none of them do. Used by the scanner and the watcher hot tier so the symbol-index stays consistent with files_ir even if a write fails partway through.

Definitions and imports are extracted from file via extract_definitions / extract_imports.

Source

fn get_by_path( &self, branch_id: &BranchId, file_path: &str, ) -> Result<ProjectFile, StorageError>

Get the IR for a file by its path within a branch.

Source

fn get_by_branch( &self, branch_id: &BranchId, ) -> Result<Vec<ProjectFile>, StorageError>

Get all file IR records for the given branch.

Source

fn get_file_hashes_by_branch( &self, branch_id: &BranchId, ) -> Result<HashMap<String, String>, StorageError>

Get all (file_path, content_hash) pairs for a branch.

This is more efficient than get_by_branch when you only need path + hash for incremental comparison (avoids deserializing the full IR).

Source

fn delete_by_path( &self, branch_id: &BranchId, file_path: &str, ) -> Result<(), StorageError>

Delete the IR record for a file path within a branch.

Source

fn delete_with_symbol_index( &self, branch_id: &BranchId, file_path: &str, ) -> Result<(), StorageError>

Delete the files_ir row and every matching symbol_definitions / symbol_imports row for (branch_id, file_path) in a single transaction. Pairs with Self::upsert_with_symbol_index so the watcher / scanner have one atomic write path for both add/modify and delete — readers cannot observe files_ir gone while symbol-index rows linger (or vice versa).

Returns StorageError::NotFound if no files_ir row matched; the symbol-index DELETEs are still attempted inside the same transaction (orphan symbol rows from an earlier non-atomic write are cleaned up).

Source

fn check_content_hash( &self, branch_id: &BranchId, file_path: &str, content_hash: &str, ) -> Result<bool, StorageError>

Check whether the stored content hash matches the given hash. Returns true if a record exists and the hash matches, false otherwise.

Source

fn get_file_dates_by_branch( &self, branch_id: &BranchId, ) -> Result<HashMap<String, Option<i64>>, StorageError>

Get all (file_path, last_commit_date) pairs for a branch.

Returns a map of file paths to their most recent git commit timestamps. Files without a recorded date are included with None.

Source

fn update_convention_compliance_counts( &self, branch_id: &BranchId, counts: &HashMap<String, u32>, ) -> Result<(), StorageError>

Update convention_compliance_count for multiple files in a single transaction.

counts maps file_path → compliance count (number of follows_convention == true findings for that file).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§