MCPcopy Create free account
hub / github.com/cosdata/cosdata / load_collection

Method load_collection

src/models/collection_cache.rs:105–146  ·  view source on GitHub ↗
(&self, name: &str)

Source from the content-addressed store, hash-verified

103 }
104
105 pub fn load_collection(&self, name: &str) -> Result<Arc<CollectionCacheEntry>, WaCustomError> {
106 // Get or create key for this collection name
107 let key = self.get_or_create_key(name);
108
109 // Try to get from cache first - this will update LRU tracking
110 if let Some(entry) = self.cache.get(&key) {
111 info!("Collection '{}' found in cache", name);
112 return Ok(entry);
113 }
114
115 // If not in cache, load it
116 info!("Loading collection '{}' into cache", name);
117 let collection_path = self.collections_path.join(name);
118 if !collection_path.exists() {
119 return Err(WaCustomError::NotFound(format!(
120 "Collection '{}' not found",
121 name
122 )));
123 }
124
125 // Load dense and inverted indexes
126 let dense_index = self.load_dense_index(name)?;
127 let inverted_index = self.load_inverted_index(name)?;
128
129 // Create cache entry
130 let entry = Arc::new(CollectionCacheEntry {
131 name: name.to_string(),
132 dense_index,
133 inverted_index,
134 last_accessed: Instant::now(),
135 });
136
137 // Add to cache - this may trigger eviction if at capacity
138 self.cache.insert(key, entry.clone());
139 info!(
140 "Added collection '{}' to cache. Current loaded collections count: {}",
141 name,
142 self.name_to_key.len()
143 );
144
145 Ok(entry)
146 }
147
148 pub fn unload_collection(&self, name: &str) -> Result<(), WaCustomError> {
149 // Clean up mappings

Callers 2

load_collectionFunction · 0.80

Calls 6

get_or_create_keyMethod · 0.80
load_dense_indexMethod · 0.80
cloneMethod · 0.80
getMethod · 0.45
load_inverted_indexMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected