diff --git a/crates/re_space_view_text_log/Cargo.toml b/crates/re_space_view_text_log/Cargo.toml index 040f317fbd18..11f7623e747c 100644 --- a/crates/re_space_view_text_log/Cargo.toml +++ b/crates/re_space_view_text_log/Cargo.toml @@ -22,6 +22,7 @@ re_entity_db.workspace = true re_log_types.workspace = true re_log.workspace = true re_query_cache.workspace = true +re_query_cache2.workspace = true re_renderer.workspace = true re_tracing.workspace = true re_types.workspace = true diff --git a/crates/re_space_view_text_log/src/visualizer_system.rs b/crates/re_space_view_text_log/src/visualizer_system.rs index 76a46b084151..ddfb1b91bcff 100644 --- a/crates/re_space_view_text_log/src/visualizer_system.rs +++ b/crates/re_space_view_text_log/src/visualizer_system.rs @@ -1,9 +1,11 @@ -use re_data_store::TimeRange; +use re_data_store::{RangeQuery, TimeRange}; use re_entity_db::EntityPath; use re_log_types::{RowId, TimeInt}; +use re_query_cache2::{clamped_zip_1x2, range_zip_1x2, CachedRangeData, PromiseResult}; use re_types::{ archetypes::TextLog, components::{Color, Text, TextLogLevel}, + Component, Loggable as _, }; use re_viewer_context::{ IdentifiedViewSystem, SpaceViewSystemExecutionError, ViewContextCollection, ViewQuery, @@ -46,41 +48,71 @@ impl VisualizerSystem for TextLogSystem { fn execute( &mut self, ctx: &ViewerContext<'_>, - query: &ViewQuery<'_>, + view_query: &ViewQuery<'_>, _view_ctx: &ViewContextCollection, ) -> Result, SpaceViewSystemExecutionError> { - let query_caches = ctx.recording().query_caches(); let store = ctx.recording_store(); + let query_caches2 = ctx.recording().query_caches2(); + let resolver = ctx.recording().resolver(); - for data_result in query.iter_visible_data_results(ctx, Self::identifier()) { - re_tracing::profile_scope!("primary", &data_result.entity_path.to_string()); + // We want everything, for all times: + let query = re_data_store::RangeQuery::new(view_query.timeline, TimeRange::EVERYTHING); - // We want everything, for all times: - let timeline_query = - re_data_store::RangeQuery::new(query.timeline, TimeRange::EVERYTHING); + for data_result in view_query.iter_visible_data_results(ctx, Self::identifier()) { + re_tracing::profile_scope!("primary", &data_result.entity_path.to_string()); - // TODO(cmc): use raw API. - query_caches.query_archetype_pov1_comp2::( + let results = query_caches2.range( store, - &timeline_query.clone().into(), + &query, &data_result.entity_path, - |((time, row_id), _, bodies, levels, colors)| { - for (body, level, color) in itertools::izip!( - bodies.iter(), - re_query_cache::iter_or_repeat_opt(levels, bodies.len()), - re_query_cache::iter_or_repeat_opt(colors, bodies.len()), - ) { - self.entries.push(Entry { - row_id, - entity_path: data_result.entity_path.clone(), - time, - color: *color, - body: body.clone(), - level: level.clone(), - }); - } - }, - )?; + [Text::name(), TextLogLevel::name(), Color::name()], + ); + + let all_bodies = { + let Some(all_bodies) = results.get(Text::name()) else { + continue; + }; + all_bodies.to_dense::(resolver) + }; + check_range(&query, &all_bodies)?; + + let all_levels = results + .get_or_empty(TextLogLevel::name()) + .to_dense::(resolver); + check_range(&query, &all_levels)?; + + let all_colors = results + .get_or_empty(Color::name()) + .to_dense::(resolver); + check_range(&query, &all_colors)?; + + let all_frames = range_zip_1x2( + all_bodies.range_indexed(query.range()), + all_levels.range_indexed(query.range()), + all_colors.range_indexed(query.range()), + ); + + for (&(data_time, row_id), bodies, levels, colors) in all_frames { + let levels = levels.unwrap_or(&[]).iter().cloned().map(Some); + let colors = colors.unwrap_or(&[]).iter().copied().map(Some); + + let level_default_fn = || None; + let color_default_fn = || None; + + let results = + clamped_zip_1x2(bodies, levels, level_default_fn, colors, color_default_fn); + + for (body, level, color) in results { + self.entries.push(Entry { + row_id, + entity_path: data_result.entity_path.clone(), + time: data_time, + color, + body: body.clone(), + level, + }); + } + } } { @@ -96,3 +128,24 @@ impl VisualizerSystem for TextLogSystem { self } } + +// TODO(#5607): what should happen if the promise is still pending? +#[inline] +fn check_range<'a, C: Component>( + query: &RangeQuery, + results: &'a CachedRangeData<'a, C>, +) -> re_query_cache2::Result<()> { + let (front_status, back_status) = results.status(query.range()); + match front_status { + PromiseResult::Pending => return Ok(()), + PromiseResult::Error(err) => return Err(re_query_cache2::QueryError::Other(err.into())), + PromiseResult::Ready(_) => {} + } + match back_status { + PromiseResult::Pending => return Ok(()), + PromiseResult::Error(err) => return Err(re_query_cache2::QueryError::Other(err.into())), + PromiseResult::Ready(_) => {} + } + + Ok(()) +}