| 139 | } |
| 140 | |
| 141 | fn insert(&self, key: UserKey, value: User) -> Option<User> { |
| 142 | DB.with(|m| { |
| 143 | CACHE.with(|cache| cache.borrow_mut().insert(key.id, value.clone())); |
| 144 | |
| 145 | let prev = m.borrow_mut().insert(key, value.clone()); |
| 146 | |
| 147 | // Update metrics when a user is upserted. |
| 148 | USER_METRICS.with(|metrics| { |
| 149 | metrics |
| 150 | .iter() |
| 151 | .for_each(|metric| metric.borrow_mut().sum(&value, prev.as_ref())) |
| 152 | }); |
| 153 | |
| 154 | self.save_entry_indexes(&value, prev.as_ref()); |
| 155 | |
| 156 | let args = (value, prev); |
| 157 | self.change_observer.notify(&args); |
| 158 | |
| 159 | args.1 |
| 160 | }) |
| 161 | } |
| 162 | |
| 163 | fn remove(&self, key: &UserKey) -> Option<User> { |
| 164 | DB.with(|m| { |