global: snapshot

This commit is contained in:
nym21
2026-03-02 19:44:45 +01:00
parent 4e7cd9ab6f
commit ccb2db2309
37 changed files with 337 additions and 1412 deletions

View File

@@ -255,13 +255,9 @@ impl CohortState {
self.cost_basis_data.compute_percentiles()
}
pub(crate) fn compute_unrealized_states(
&mut self,
height_price: Cents,
date_price: Option<Cents>,
) -> (UnrealizedState, Option<UnrealizedState>) {
pub(crate) fn compute_unrealized_state(&mut self, height_price: Cents) -> UnrealizedState {
self.cost_basis_data
.compute_unrealized_states(height_price, date_price)
.compute_unrealized_state(height_price)
}
pub(crate) fn write(&mut self, height: Height, cleanup: bool) -> Result<()> {

View File

@@ -257,33 +257,21 @@ impl CostBasisData {
self.cached_percentiles
}
pub(crate) fn compute_unrealized_states(
&mut self,
height_price: Cents,
date_price: Option<Cents>,
) -> (UnrealizedState, Option<UnrealizedState>) {
pub(crate) fn compute_unrealized_state(&mut self, height_price: Cents) -> UnrealizedState {
if self.is_empty() {
return (
UnrealizedState::ZERO,
date_price.map(|_| UnrealizedState::ZERO),
);
return UnrealizedState::ZERO;
}
let map = &self.state.as_ref().unwrap().base.map;
let date_state =
date_price.map(|p| CachedUnrealizedState::compute_full_standalone(p.into(), map));
let height_state = if let Some(cache) = self.cache.as_mut() {
if let Some(cache) = self.cache.as_mut() {
cache.get_at_price(height_price, map)
} else {
let cache = CachedUnrealizedState::compute_fresh(height_price, map);
let state = cache.current_state();
self.cache = Some(cache);
state
};
(height_state, date_state)
}
}
pub(crate) fn clean(&mut self) -> Result<()> {

View File

@@ -280,12 +280,4 @@ impl CachedUnrealizedState {
state
}
/// Compute final UnrealizedState directly (not cached).
/// Used for date_state which doesn't use the cache.
pub(crate) fn compute_full_standalone(
current_price: CentsCompact,
map: &CostBasisMap,
) -> UnrealizedState {
Self::compute_raw(current_price, map).to_output()
}
}