(lmdb: &MetaDb)
| 250 | } |
| 251 | |
| 252 | pub fn retrieve_average_document_length(lmdb: &MetaDb) -> Result<Option<f32>, WaCustomError> { |
| 253 | let env = lmdb.env.clone(); |
| 254 | let db = lmdb.db; |
| 255 | let txn = env |
| 256 | .begin_ro_txn() |
| 257 | .map_err(|e| WaCustomError::DatabaseError(format!("Failed to begin transaction: {}", e)))?; |
| 258 | let key = key!(m:average_document_length); |
| 259 | |
| 260 | let serialized = match txn.get(db, &key) { |
| 261 | Ok(bytes) => bytes, |
| 262 | Err(lmdb::Error::NotFound) => return Ok(None), |
| 263 | Err(e) => return Err(WaCustomError::DatabaseError(e.to_string())), |
| 264 | }; |
| 265 | |
| 266 | let bytes: [u8; 4] = serialized.try_into().map_err(|_| { |
| 267 | WaCustomError::DeserializationError( |
| 268 | "Failed to deserialize average document length: length mismatch".to_string(), |
| 269 | ) |
| 270 | })?; |
| 271 | let len = f32::from_le_bytes(bytes); |
| 272 | |
| 273 | Ok(Some(len)) |
| 274 | } |
| 275 | |
| 276 | pub fn retrieve_highest_internal_id(lmdb: &MetaDb) -> Result<Option<u32>, WaCustomError> { |
| 277 | let env = lmdb.env.clone(); |
no test coverage detected