Outdent state_compressor service.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-04-29 06:55:54 +00:00 committed by Jade Ellis
parent c5c309ec43
commit 56420a67ca
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2

View file

@ -9,7 +9,7 @@ use async_trait::async_trait;
use conduwuit::{ use conduwuit::{
Result, Result,
arrayvec::ArrayVec, arrayvec::ArrayVec,
at, checked, err, expected, utils, at, checked, err, expected, implement, utils,
utils::{bytes, math::usize_from_f64, stream::IterStream}, utils::{bytes, math::usize_from_f64, stream::IterStream},
}; };
use database::Map; use database::Map;
@ -115,9 +115,9 @@ impl crate::Service for Service {
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) } fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
} }
impl Service {
/// Returns a stack with info on shortstatehash, full state, added diff and /// Returns a stack with info on shortstatehash, full state, added diff and
/// removed diff for the selected shortstatehash and each parent layer. /// removed diff for the selected shortstatehash and each parent layer.
#[implement(Service)]
#[tracing::instrument(name = "load", level = "debug", skip(self))] #[tracing::instrument(name = "load", level = "debug", skip(self))]
pub async fn load_shortstatehash_info( pub async fn load_shortstatehash_info(
&self, &self,
@ -137,6 +137,7 @@ impl Service {
/// Returns a stack with info on shortstatehash, full state, added diff and /// Returns a stack with info on shortstatehash, full state, added diff and
/// removed diff for the selected shortstatehash and each parent layer. /// removed diff for the selected shortstatehash and each parent layer.
#[implement(Service)]
#[tracing::instrument( #[tracing::instrument(
name = "cache", name = "cache",
level = "debug", level = "debug",
@ -156,6 +157,7 @@ impl Service {
Ok(()) Ok(())
} }
#[implement(Service)]
async fn new_shortstatehash_info( async fn new_shortstatehash_info(
&self, &self,
shortstatehash: ShortStateHash, shortstatehash: ShortStateHash,
@ -192,6 +194,7 @@ impl Service {
Ok(stack) Ok(stack)
} }
#[implement(Service)]
pub fn compress_state_events<'a, I>( pub fn compress_state_events<'a, I>(
&'a self, &'a self,
state: I, state: I,
@ -210,11 +213,10 @@ impl Service {
.stream() .stream()
.map(at!(0)) .map(at!(0))
.zip(short_event_ids) .zip(short_event_ids)
.map(|(shortstatekey, shorteventid)| { .map(|(shortstatekey, shorteventid)| compress_state_event(*shortstatekey, shorteventid))
compress_state_event(*shortstatekey, shorteventid)
})
} }
#[implement(Service)]
pub async fn compress_state_event( pub async fn compress_state_event(
&self, &self,
shortstatekey: ShortStateKey, shortstatekey: ShortStateKey,
@ -243,10 +245,11 @@ impl Service {
/// * `statediffnew` - Added to base. Each vec is shortstatekey+shorteventid /// * `statediffnew` - Added to base. Each vec is shortstatekey+shorteventid
/// * `statediffremoved` - Removed from base. Each vec is /// * `statediffremoved` - Removed from base. Each vec is
/// shortstatekey+shorteventid /// shortstatekey+shorteventid
/// * `diff_to_sibling` - Approximately how much the diff grows each time /// * `diff_to_sibling` - Approximately how much the diff grows each time for
/// for this layer /// this layer
/// * `parent_states` - A stack with info on shortstatehash, full state, /// * `parent_states` - A stack with info on shortstatehash, full state, added
/// added diff and removed diff for each parent layer /// diff and removed diff for each parent layer
#[implement(Service)]
pub fn save_state_from_diff( pub fn save_state_from_diff(
&self, &self,
shortstatehash: ShortStateHash, shortstatehash: ShortStateHash,
@ -360,6 +363,7 @@ impl Service {
/// Returns the new shortstatehash, and the state diff from the previous /// Returns the new shortstatehash, and the state diff from the previous
/// room state /// room state
#[implement(Service)]
#[tracing::instrument(skip(self, new_state_ids_compressed), level = "debug")] #[tracing::instrument(skip(self, new_state_ids_compressed), level = "debug")]
pub async fn save_state( pub async fn save_state(
&self, &self,
@ -395,8 +399,7 @@ impl Service {
ShortStateInfoVec::new() ShortStateInfoVec::new()
}; };
let (statediffnew, statediffremoved) = let (statediffnew, statediffremoved) = if let Some(parent_stateinfo) = states_parents.last() {
if let Some(parent_stateinfo) = states_parents.last() {
let statediffnew: CompressedState = new_state_ids_compressed let statediffnew: CompressedState = new_state_ids_compressed
.difference(&parent_stateinfo.full_state) .difference(&parent_stateinfo.full_state)
.copied() .copied()
@ -430,6 +433,7 @@ impl Service {
}) })
} }
#[implement(Service)]
#[tracing::instrument(skip(self), level = "debug", name = "get")] #[tracing::instrument(skip(self), level = "debug", name = "get")]
async fn get_statediff(&self, shortstatehash: ShortStateHash) -> Result<StateDiff> { async fn get_statediff(&self, shortstatehash: ShortStateHash) -> Result<StateDiff> {
const BUFSIZE: usize = size_of::<ShortStateHash>(); const BUFSIZE: usize = size_of::<ShortStateHash>();
@ -477,6 +481,7 @@ impl Service {
}) })
} }
#[implement(Service)]
fn save_statediff(&self, shortstatehash: ShortStateHash, diff: &StateDiff) { fn save_statediff(&self, shortstatehash: ShortStateHash, diff: &StateDiff) {
let mut value = Vec::<u8>::with_capacity( let mut value = Vec::<u8>::with_capacity(
2_usize 2_usize
@ -502,7 +507,6 @@ impl Service {
.shortstatehash_statediff .shortstatehash_statediff
.insert(&shortstatehash.to_be_bytes(), &value); .insert(&shortstatehash.to_be_bytes(), &value);
} }
}
#[inline] #[inline]
#[must_use] #[must_use]