pub(in crate::data::executor::handlers::snapshot) fn parse_timeseries_snapshot_key(
key: &str,
) -> (u64, u64, String) {
let mut it = key.splitn(3, ':');
let first = it.next().unwrap_or("");
let second = it.next();
let third = it.next();
match (second, third) {
(Some(tenant), Some(collection)) => {
let db = first.parse::<u64>().unwrap_or(0);
let tid = tenant.parse::<u64>().unwrap_or(0);
(db, tid, collection.to_string())
}
(Some(collection), None) => {
let tid = first.parse::<u64>().unwrap_or(0);
(0, tid, collection.to_string())
}
_ => (0, 0, first.to_string()),
}
}
pub(super) fn parse_vector_snapshot_key(key: &str, tenant_id: u64) -> (u64, &str) {
let mut it = key.splitn(3, ':');
let first = it.next().unwrap_or("");
let second = it.next();
let third = it.next();
if let (Some(second), Some(_)) = (second, third)
&& let (Ok(db), Ok(_tid)) = (first.parse::<u64>(), second.parse::<u64>())
{
let prefix_len = first.len() + 1 + second.len() + 1;
return (db, &key[prefix_len..]);
}
let tid_prefix = format!("{tenant_id}:");
let coll_key = key.strip_prefix(&tid_prefix).unwrap_or(key);
(0, coll_key)
}
pub(in crate::data::executor) fn database_id_from_qualified(collection: &str) -> u64 {
match collection.split_once('/') {
Some((prefix, _)) => prefix.parse::<u64>().unwrap_or(0),
None => 0,
}
}