fix: de-index pdus when redacted

This commit is contained in:
Matthias Ahouansou 2024-06-05 20:17:32 +01:00 committed by Charles Hall
parent cc5a9d3440
commit f74043df9a
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 50 additions and 2 deletions

View file

@ -33,6 +33,29 @@ impl service::rooms::search::Data for KeyValueDatabase {
self.tokenids.insert_batch(&mut batch)
}
#[tracing::instrument(skip(self))]
fn deindex_pdu(
&self,
shortroomid: u64,
pdu_id: &[u8],
message_body: &str,
) -> Result<()> {
let batch = tokenize(message_body).map(|word| {
let mut key = shortroomid.to_be_bytes().to_vec();
key.extend_from_slice(word.as_bytes());
key.push(0xFF);
// TODO: currently we save the room id a second time here
key.extend_from_slice(pdu_id);
key
});
for token in batch {
self.tokenids.remove(&token)?;
}
Ok(())
}
#[tracing::instrument(skip(self))]
#[allow(clippy::type_complexity)]
fn search_pdus<'a>(