use crate::data::executor::core_loop::CoreLoop;
pub(in crate::data::executor) struct UpdateSparseReindex<'a> {
pub database_id: u64,
pub tid: u64,
pub collection: &'a str,
pub row_key: &'a str,
pub new_body: &'a [u8],
pub is_strict: bool,
pub has_sparse: bool,
}
impl CoreLoop {
pub(in crate::data::executor) fn update_reindex_sparse_indexes(
&mut self,
p: UpdateSparseReindex<'_>,
) {
if !p.has_sparse {
return;
}
self.remove_document_sparse_indexes(p.database_id, p.tid, p.collection, p.row_key);
let owned_mp;
let mp: &[u8] = if p.is_strict {
let config_key = (
crate::types::DatabaseId::new(p.database_id),
crate::types::TenantId::new(p.tid),
p.collection.to_string(),
);
let Some(config) = self.doc_configs.get(&config_key) else {
return;
};
let Some(doc) = self.decode_stored_document(config, p.new_body) else {
return;
};
let Ok(mp) = nodedb_types::json_to_msgpack(&doc) else {
return;
};
owned_mp = mp;
&owned_mp
} else {
p.new_body
};
self.apply_point_put_sparse_indexes(p.database_id, p.tid, p.collection, p.row_key, mp);
}
}