Skip to content

Commit

Permalink
yep, i hate git
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Apr 19, 2024
1 parent 8f648b8 commit 89b2102
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 487 deletions.
6 changes: 3 additions & 3 deletions crates/re_query/examples/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use re_log_types::example_components::{MyColor, MyLabel, MyPoint, MyPoints};
use re_log_types::{build_frame_nr, DataRow, RowId, TimeRange, TimeType, Timeline};
use re_types_core::{Archetype as _, Loggable as _};

use re_query_cache::{
clamped_zip_1x2, range_zip_1x2, CachedRangeComponentResults, CachedRangeResults,
use re_query::{
clamped_zip_1x2, range_zip_1x2, RangeComponentResults, RangeResults,
PromiseResolver, PromiseResult,
};

Expand All @@ -22,7 +22,7 @@ fn main() -> anyhow::Result<()> {
let query = RangeQuery::new(timeline, TimeRange::EVERYTHING);
eprintln!("query:{query:?}");

let caches = re_query_cache::Caches::new(&store);
let caches = re_query::Caches::new(&store);

// First, get the raw results for this query.
//
Expand Down
8 changes: 3 additions & 5 deletions crates/re_query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ pub use self::visible_history::{ExtraQueryHistory, VisibleHistory, VisibleHistor
pub use self::cache::{CacheKey, Caches};
pub use self::cache_stats::{CachedComponentStats, CachesStats};
pub use self::flat_vec_deque::{ErasedFlatVecDeque, FlatVecDeque};
pub use self::latest_at::{
LatestAtComponentResults, CachedLatestAtMonoResult, LatestAtResults,
};
pub use self::range::{RangeComponentResults, CachedRangeData, RangeResults};
pub use self::latest_at::{CachedLatestAtMonoResult, LatestAtComponentResults, LatestAtResults};
pub use self::range::{CachedRangeData, RangeComponentResults, RangeResults};

pub(crate) use self::latest_at::LatestAtCache;
pub(crate) use self::range::{RangeComponentResultsInner, RangeCache};
pub(crate) use self::range::{RangeCache, RangeComponentResultsInner};

pub mod external {
pub use paste;
Expand Down
2 changes: 1 addition & 1 deletion crates/re_query/src/range/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Caches {
) -> RangeResults {
re_tracing::profile_function!(entity_path.to_string());

let mut results = CachedRangeResults::new(query.clone());
let mut results = RangeResults::new(query.clone());

for component_name in component_names {
let key = CacheKey::new(entity_path.clone(), query.timeline(), component_name);
Expand Down
28 changes: 11 additions & 17 deletions crates/re_query/src/range/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ use crate::{ErasedFlatVecDeque, FlatVecDeque, Promise, PromiseResolver, PromiseR
/// Use [`RangeResults::get`], [`RangeResults::get_required`] and
/// [`RangeResults::get_or_empty`] in order to access the results for each individual component.
#[derive(Debug)]
pub struct CachedRangeResults {
pub struct RangeResults {
pub query: RangeQuery,
pub components: IntMap<ComponentName, CachedRangeComponentResults>,
pub components: IntMap<ComponentName, RangeComponentResults>,
}

impl CachedRangeResults {
impl RangeResults {
#[inline]
pub(crate) fn new(query: RangeQuery) -> Self {
Self {
Expand All @@ -44,10 +44,7 @@ impl CachedRangeResults {

/// Returns the [`RangeComponentResults`] for the specified [`Component`].
#[inline]
pub fn get(
&self,
component_name: impl Into<ComponentName>,
) -> Option<&RangeComponentResults> {
pub fn get(&self, component_name: impl Into<ComponentName>) -> Option<&RangeComponentResults> {
self.components.get(&component_name.into())
}

Expand Down Expand Up @@ -75,10 +72,7 @@ impl CachedRangeResults {
///
/// Returns empty results if the component is not present.
#[inline]
pub fn get_or_empty(
&self,
component_name: impl Into<ComponentName>,
) -> &RangeComponentResults {
pub fn get_or_empty(&self, component_name: impl Into<ComponentName>) -> &RangeComponentResults {
let component_name = component_name.into();
if let Some(component) = self.components.get(&component_name) {
component
Expand All @@ -100,17 +94,17 @@ impl RangeResults {

/// Lazily cached results for a particular component when using a cached range query.
#[derive(Debug)]
pub struct CachedRangeComponentResults {
pub struct RangeComponentResults {
/// The [`TimeRange`] of the query that was used in order to retrieve these results in the
/// first place.
///
/// The "original" copy in the cache just stores [`TimeRange::EMPTY`]. It's meaningless.
pub(crate) time_range: TimeRange,

pub(crate) inner: Arc<RwLock<CachedRangeComponentResultsInner>>,
pub(crate) inner: Arc<RwLock<RangeComponentResultsInner>>,
}

impl CachedRangeComponentResults {
impl RangeComponentResults {
/// Clones the results while making sure to stamp them with the [`TimeRange`] of the associated query.
#[inline]
pub(crate) fn clone_at(&self, time_range: TimeRange) -> Self {
Expand All @@ -124,8 +118,8 @@ impl CachedRangeComponentResults {
impl RangeComponentResults {
#[inline]
pub fn empty() -> &'static Self {
static EMPTY: OnceLock<CachedRangeComponentResults> = OnceLock::new();
EMPTY.get_or_init(CachedRangeComponentResults::default)
static EMPTY: OnceLock<RangeComponentResults> = OnceLock::new();
EMPTY.get_or_init(RangeComponentResults::default)
}
}

Expand All @@ -142,7 +136,7 @@ impl Default for RangeComponentResults {
fn default() -> Self {
Self {
time_range: TimeRange::EMPTY,
inner: Arc::new(RwLock::new(CachedRangeComponentResultsInner::empty())),
inner: Arc::new(RwLock::new(RangeComponentResultsInner::empty())),
}
}
}
Expand Down
Loading

0 comments on commit 89b2102

Please sign in to comment.