MCPcopy Create free account
hub / github.com/dfinity/orbit / build_cache

Method build_cache

core/station/impl/src/repositories/user_group.rs:160–178  ·  view source on GitHub ↗

Builds the cache from the stable memory repository. This method should only be called during init or upgrade hooks to ensure that the cache is up-to-date with the repository and that we have enough instructions to rebuild the cache.

(&self)

Source from the content-addressed store, hash-verified

158 /// This method should only be called during init or upgrade hooks to ensure that the cache is
159 /// up-to-date with the repository and that we have enough instructions to rebuild the cache.
160 pub fn build_cache(&self) {
161 if self.len() > Self::MAX_CACHE_SIZE {
162 print(format!(
163 "Only the first {} user groups will be added to the cache, the reposity has {} user groups.",
164 Self::MAX_CACHE_SIZE,
165 self.len(),
166 ));
167 }
168
169 CACHE.with(|cache| {
170 cache.borrow_mut().clear();
171
172 DB.with(|db| {
173 for (_, user_group) in db.borrow().iter().take(Self::MAX_CACHE_SIZE) {
174 cache.borrow_mut().insert(user_group.id, user_group);
175 }
176 });
177 });
178 }
179
180 pub fn find_by_name(&self, name: &str) -> Option<UserGroup> {
181 self.unique_index

Callers

nothing calls this directly

Calls 5

printFunction · 0.85
iterMethod · 0.80
lenMethod · 0.45
clearMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected