Skip to content

Commit

Permalink
Fix the time_range to include pending data
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed May 13, 2024
1 parent 55beed9 commit ee90c86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/re_query/src/cache_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Caches {
(
key.clone(),
(
cache.time_range(),
cache.pending_time_range(),
CachedComponentStats {
total_indices: cache.indices.len() as _,
total_instances: cache.num_instances(),
Expand Down
6 changes: 3 additions & 3 deletions crates/re_query/src/range/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Caches {
// and coarsly invalidates the whole cache in that case, to avoid the kind of bugs
// showcased in <https://github.com/rerun-io/rerun/issues/5686>.
{
let time_range = cache.per_data_time.read_recursive().time_range();
let time_range = cache.per_data_time.read_recursive().pending_time_range();
if let Some(time_range) = time_range {
{
let hole_start = time_range.max();
Expand Down Expand Up @@ -373,7 +373,7 @@ impl RangeComponentResultsInner {
});
let pending_min = i64::min(pending_front_min, pending_back_min);

if let Some(time_range) = self.time_range() {
if let Some(time_range) = self.pending_time_range() {
let time_range_min = i64::min(time_range.min().as_i64().saturating_sub(1), pending_min);
reduced_query
.range
Expand Down Expand Up @@ -454,7 +454,7 @@ impl RangeComponentResultsInner {
});
let pending_max = i64::max(pending_back_max, pending_front_max);

if let Some(time_range) = self.time_range() {
if let Some(time_range) = self.pending_time_range() {
let time_range_max = i64::max(time_range.max().as_i64().saturating_add(1), pending_max);
reduced_query
.range
Expand Down
20 changes: 14 additions & 6 deletions crates/re_query/src/range/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,14 +776,22 @@ impl RangeComponentResultsInner {
}
}

/// Returns the time range covered by the cached data.
/// Returns the pending time range that will be covered by the cached data.
///
/// Reminder: [`TimeInt::STATIC`] is never included in [`ResolvedTimeRange`]s.
#[inline]
pub fn time_range(&self) -> Option<ResolvedTimeRange> {
let first_time = self.indices.front().map(|(t, _)| *t)?;
let last_time = self.indices.back().map(|(t, _)| *t)?;
Some(ResolvedTimeRange::new(first_time, last_time))
pub fn pending_time_range(&self) -> Option<ResolvedTimeRange> {
let pending_front_min = self.promises_front.first().map(|((t, _), _)| *t);
let pending_front_back = self.promises_front.first().map(|((t, _), _)| *t);
let pending_back_max = self.promises_back.last().map(|((t, _), _)| *t);

let first_time = self.indices.front().map(|(t, _)| *t);
let last_time = self.indices.back().map(|(t, _)| *t);

Some(ResolvedTimeRange::new(
pending_front_min.or(first_time)?,
pending_back_max.or(last_time).or(pending_front_back)?,
))
}

#[inline]
Expand All @@ -801,7 +809,7 @@ impl RangeComponentResultsInner {
pub fn truncate_at_time(&mut self, threshold: TimeInt) {
re_tracing::profile_function!();

let time_range = self.time_range();
let time_range = self.pending_time_range();

let Self {
indices,
Expand Down

0 comments on commit ee90c86

Please sign in to comment.