tuwunel_service/migrations/
split_conduit_highlight_counts.rs1use tuwunel_core::{Result, info, utils::TryReadyExt};
2use tuwunel_database::Map;
3
4use super::tally::{Outcome, Tally};
5use crate::{
6 Services,
7 integrity::userroomid_highlightcount::{Finding, scan},
8};
9
10pub(super) async fn split_conduit_highlight_counts(services: &Services) -> Result {
19 let db = &services.db;
20 let highlight = &db["userroomid_highlightcount"];
21 let lastread = &db["roomuserid_lastnotificationread"];
22
23 let (tally, cork) = scan(services)
25 .ready_try_fold((Tally::default(), None), |(tally, cork), finding| {
26 let cork = cork.or_else(|| Some(db.cork_and_sync()));
27
28 Ok((tally.record(repair(highlight, lastread, &finding)), cork))
29 })
30 .await?;
31
32 drop(cork);
33
34 if tally.repaired > 0 {
35 info!(
36 moved = %tally.repaired,
37 "Split Conduit last-notification-read rows out of the highlight-count column"
38 );
39 }
40
41 Ok(())
42}
43
44fn repair(highlight: &Map, lastread: &Map, Finding { key, value }: &Finding) -> Outcome {
50 lastread.insert(key, value);
51 highlight.remove(key);
52
53 Outcome::Repaired
54}