Expand description
§UpdateState
§File: Indexing/State/UpdateState.rs
§Role in Air Architecture
Provides state update operations for the File Indexer service, handling modification of index structures including adding, removing, and updating entries in the file index.
§Primary Responsibility
Update file index state by adding/removing files, symbols, and content entries in a thread-safe manner.
§Secondary Responsibilities
- Remove deleted files from all indexes
- Update symbol index with new symbol locations
- Update content index with new file paths
- Maintain index version and checksum on updates
§Dependencies
External Crates:
tokio- Async runtime for update operations
Internal Modules:
crate::Result- Error handling typecrate::AirError- Error typessuper::CreateState- State structure definitions
§Dependents
Indexing::Scan::ScanDirectory- Updates index after directory scanIndexing::Scan::ScanFile- Updates index after file scanIndexing::Store::UpdateIndex- Incremental index updatesIndexing::Watch::WatchFile- Updates index on file changes
§VSCode Pattern Reference
Inspired by VSCode’s index update operations in
src/vs/workbench/services/search/common/
§Security Considerations
- Thread-safe updates prevent race conditions
- Path validation before state updates
- Size limits enforced on all update operations
§Performance Considerations
- Incremental updates minimize reindexing
- Batch updates for multiple files
- Efficient hash lookups for O(1) updates
§Error Handling Strategy
Update operations silently fail on missing keys (idempotent) and propagate errors for I/O failures or invalid state transitions.
§Thread Safety
All update operations are designed to work within RwLock write guards and should be called while holding appropriate locks.
Functions§
- AddFile
ToIndex - Add a file to the index with its metadata and symbols
- Cleanup
Orphaned Entries - Clean up orphaned entries (files with no matching content/symbols)
- GetIndex
Size Estimate - Get index size estimate in bytes
- Merge
Indexes - Merge another index into this one
- Needs
Update - Check if periodic update is needed based on age
- Remove
File From Index - Remove a file from all indexes (content, symbols, files)
- Remove
Files From Index - Remove multiple files from the index in a batch operation
- Update
Content Index - Update content index for a file
- Update
File Metadata - Update file metadata for an existing file
- Update
File Symbols - Update symbols for a file
- Update
Index Metadata - Update index metadata (version, timestamp, checksum)
- Validate
Index Consistency - Validate that index is in a consistent state