mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 23:31:24 +01:00
wip: delete all accepted/outlier PDUs
This commit is contained in:
parent
7d5795d868
commit
ed401fb041
1 changed files with 85 additions and 0 deletions
|
|
@ -4,9 +4,94 @@
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
use ruma::RoomId;
|
||||||
|
use tracing as t;
|
||||||
|
|
||||||
use super::DeleteRoomArgs;
|
use super::DeleteRoomArgs;
|
||||||
|
use crate::{
|
||||||
|
config, database::KeyValueDatabase, services, utils, PduEvent, Services,
|
||||||
|
};
|
||||||
|
|
||||||
/// Subcommand entrypoint
|
/// Subcommand entrypoint
|
||||||
pub(crate) async fn run(args: DeleteRoomArgs) -> Result<(), Box<dyn Error>> {
|
pub(crate) async fn run(args: DeleteRoomArgs) -> Result<(), Box<dyn Error>> {
|
||||||
|
let config = config::load(args.config.config.as_ref()).await?;
|
||||||
|
|
||||||
|
let db = Box::leak(Box::new(KeyValueDatabase::load_or_create(&config)?));
|
||||||
|
|
||||||
|
Services::build(db, config, None)?.install();
|
||||||
|
|
||||||
|
services().globals.err_if_server_name_changed()?;
|
||||||
|
|
||||||
|
db.apply_migrations().await?;
|
||||||
|
|
||||||
|
pdus(db, &args.room_id);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Delete PDUs
|
||||||
|
fn pdus(db: &KeyValueDatabase, room_id: &RoomId) {
|
||||||
|
let mut count = 0_usize;
|
||||||
|
|
||||||
|
let filter_map = |(k, v): (Vec<u8>, Vec<u8>)| {
|
||||||
|
let pdu = match serde_json::from_slice::<PduEvent>(&v) {
|
||||||
|
Ok(x) => x,
|
||||||
|
Err(error) => {
|
||||||
|
t::warn!(
|
||||||
|
%error,
|
||||||
|
key = utils::u8_slice_to_hex(&k),
|
||||||
|
"Failed to deserialize PDU, skipping it",
|
||||||
|
);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if pdu.room_id != room_id {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some((k, pdu))
|
||||||
|
};
|
||||||
|
|
||||||
|
// Accepted PDUs
|
||||||
|
for (k, v) in db.pduid_pdu.iter().filter_map(filter_map) {
|
||||||
|
if let Err(error) = db.eventid_pduid.remove(v.event_id.as_bytes()) {
|
||||||
|
t::warn!(
|
||||||
|
%error,
|
||||||
|
key = utils::u8_slice_to_hex(&k),
|
||||||
|
"Failed to delete event ID to PDU ID relationship",
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(error) = db.pduid_pdu.remove(&k) {
|
||||||
|
t::warn!(
|
||||||
|
%error,
|
||||||
|
key = utils::u8_slice_to_hex(&k),
|
||||||
|
"Failed to delete PDU",
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Outlier PDUs
|
||||||
|
for (k, _) in db.eventid_outlierpdu.iter().filter_map(filter_map) {
|
||||||
|
if let Err(error) = db.eventid_outlierpdu.remove(&k) {
|
||||||
|
t::warn!(
|
||||||
|
%error,
|
||||||
|
key = utils::u8_slice_to_hex(&k),
|
||||||
|
"Failed to delete PDU",
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
t::info!(count, "Deleted PDUs");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue