Persist updated statistics for a column.
(
&self,
tenant_id: u64,
collection: &str,
field: &str,
stats: &ColumnStats,
)
| 213 | |
| 214 | /// Persist updated statistics for a column. |
| 215 | pub fn put( |
| 216 | &self, |
| 217 | tenant_id: u64, |
| 218 | collection: &str, |
| 219 | field: &str, |
| 220 | stats: &ColumnStats, |
| 221 | ) -> crate::Result<()> { |
| 222 | let key = format!("{tenant_id}:{collection}:{field}"); |
| 223 | let bytes = zerompk::to_msgpack_vec(stats).map_err(|e| crate::Error::Storage { |
| 224 | engine: "stats".into(), |
| 225 | detail: format!("serialize: {e}"), |
| 226 | })?; |
| 227 | let write_txn = self.db.begin_write().map_err(|e| crate::Error::Storage { |
| 228 | engine: "stats".into(), |
| 229 | detail: format!("write txn: {e}"), |
| 230 | })?; |
| 231 | { |
| 232 | let mut table = |
| 233 | write_txn |
| 234 | .open_table(COLUMN_STATS) |
| 235 | .map_err(|e| crate::Error::Storage { |
| 236 | engine: "stats".into(), |
| 237 | detail: format!("open table: {e}"), |
| 238 | })?; |
| 239 | table |
| 240 | .insert(key.as_str(), bytes.as_slice()) |
| 241 | .map_err(|e| crate::Error::Storage { |
| 242 | engine: "stats".into(), |
| 243 | detail: format!("insert: {e}"), |
| 244 | })?; |
| 245 | } |
| 246 | write_txn.commit().map_err(|e| crate::Error::Storage { |
| 247 | engine: "stats".into(), |
| 248 | detail: format!("commit: {e}"), |
| 249 | })?; |
| 250 | Ok(()) |
| 251 | } |
| 252 | |
| 253 | /// Update statistics incrementally for a document's fields. |
| 254 | /// |