diff --git a/linux/changelog.d/4119.added.md b/linux/changelog.d/4119.added.md new file mode 100644 index 0000000000..f4a31bfc48 --- /dev/null +++ b/linux/changelog.d/4119.added.md @@ -0,0 +1 @@ +A table tab's paginator says how long the page took to read. diff --git a/linux/crates/app/src/ui/browse_tab/data_handlers.rs b/linux/crates/app/src/ui/browse_tab/data_handlers.rs index 3ed7a75cb7..9f49164435 100644 --- a/linux/crates/app/src/ui/browse_tab/data_handlers.rs +++ b/linux/crates/app/src/ui/browse_tab/data_handlers.rs @@ -31,7 +31,7 @@ impl BrowseModel { self.begin_read(fx); self.reload_from_columns(ColumnFreshness::Refetch); } - DataInput::Command(command) => self.on_command(command, fx), + DataInput::Command(command) => self.on_command(*command, fx), DataInput::LinkChanged(generation) => self.on_link_changed(generation, fx), DataInput::SchemaChanged => { self.begin_read(fx); @@ -187,6 +187,7 @@ impl BrowseModel { layout, edges, seeks, + elapsed, } = reply; self.pager.land(offset, position, edges, seeks); let QueryResult { columns, rows, .. } = result; @@ -209,6 +210,7 @@ impl BrowseModel { row_count, start_ordinal: offset, filtered: !self.current_filter.is_empty(), + elapsed, }); self.shown_view = Some(self.page_view()); self.show_page(rows, offset, fx); diff --git a/linux/crates/app/src/ui/browse_tab/data_input.rs b/linux/crates/app/src/ui/browse_tab/data_input.rs index 1584704e01..0bd9611071 100644 --- a/linux/crates/app/src/ui/browse_tab/data_input.rs +++ b/linux/crates/app/src/ui/browse_tab/data_input.rs @@ -2,17 +2,11 @@ use tablepro_session::LinkGeneration; use super::BrowseCommand; -/// What changes the columns and rows the tab holds: its own reads, and -/// changes to the connection or the table under it. #[derive(Debug)] pub(crate) enum DataInput { - /// The tab is built: read the columns, then the page and the count. Start, - /// A reply to one of the tab's reads. - Command(BrowseCommand), - /// A reconnect replaced the session's connection. + // Replies own page data; keep that payload out of every queued input. + Command(Box), LinkChanged(LinkGeneration), - /// The table's definition changed. The catalog has already dropped - /// its columns, so they are read again before the page. SchemaChanged, } diff --git a/linux/crates/app/src/ui/browse_tab/fetch.rs b/linux/crates/app/src/ui/browse_tab/fetch.rs index 2c067452cf..8314d07f43 100644 --- a/linux/crates/app/src/ui/browse_tab/fetch.rs +++ b/linux/crates/app/src/ui/browse_tab/fetch.rs @@ -141,6 +141,7 @@ impl BrowseModel { let cancel = ticket.cancel.clone(); let position = self.pager.position(); let work = async move { + let started = std::time::Instant::now(); session .run_cancellable(OperationKind::Page, &cancel, move |lease, options| { let plan = plan.clone(); @@ -159,7 +160,7 @@ impl BrowseModel { } }) .await - .map(PageReply::from) + .map(|read| PageReply::new(read, started.elapsed())) }; self.deliver(ticket, work, BrowseCommand::Page, OperationError::from); } @@ -183,7 +184,7 @@ impl BrowseModel { let _delivery = crate::runtime::spawn_and_deliver(&self.tasks, work, move |joined| { let value = joined.unwrap_or_else(|failure| Err(failed(failure))); if let Some(tab) = tab.upgrade() { - tab.send(DataInput::Command(command(Stamped { stamp, value }))); + tab.send(DataInput::Command(Box::new(command(Stamped { stamp, value })))); } }); } diff --git a/linux/crates/app/src/ui/browse_tab/page_label.rs b/linux/crates/app/src/ui/browse_tab/page_label.rs index 94aefc2f11..24d3bdf33d 100644 --- a/linux/crates/app/src/ui/browse_tab/page_label.rs +++ b/linux/crates/app/src/ui/browse_tab/page_label.rs @@ -2,9 +2,34 @@ use super::page_state::PageState; use super::row_total::RowTotal; use crate::ui::format::format_thousands; -/// The paginator's text for the page on screen. pub(super) fn page_range_label(page: &PageState, total: &RowTotal) -> String { - label_with(page, total, format_thousands) + let range = label_with(page, total, format_thousands); + crate::i18n::gettext_f( + // Translators: the visible row range and elapsed page fetch time, including network time. + "{range} · {time}", + &[("range", &range), ("time", &elapsed_text(page.elapsed))], + ) +} + +fn elapsed_text(elapsed: std::time::Duration) -> String { + use crate::i18n::{gettext, gettext_f}; + + if elapsed.as_millis() == 0 { + gettext("<1 ms") + } else if elapsed.as_secs() == 0 { + let millis = (elapsed.as_micros() + 500) / 1000; + gettext_f("{n} ms", &[("n", &millis.to_string())]) + } else if elapsed.as_secs() < 60 { + gettext_f("{n} s", &[("n", &format!("{:.2}", elapsed.as_secs_f64()))]) + } else { + gettext_f( + "{minutes}m {seconds}s", + &[ + ("minutes", &(elapsed.as_secs() / 60).to_string()), + ("seconds", &(elapsed.as_secs() % 60).to_string()), + ], + ) + } } fn label_with(page: &PageState, total: &RowTotal, format: impl Fn(u64) -> String) -> String { @@ -34,10 +59,55 @@ mod tests { row_count: rows, start_ordinal: start, filtered, + elapsed: std::time::Duration::ZERO, }; label_with(&page, total, |n| english.format(n)) } + #[test] + fn a_read_is_timed_after_the_rows_in_milliseconds_then_seconds() { + use std::time::Duration; + + assert_eq!(elapsed_text(Duration::from_micros(200)), "<1 ms"); + assert_eq!(elapsed_text(Duration::ZERO), "<1 ms"); + assert_eq!(elapsed_text(Duration::from_millis(1)), "1 ms"); + assert_eq!(elapsed_text(Duration::from_micros(5_600)), "6 ms"); + assert_eq!(elapsed_text(Duration::from_millis(5)), "5 ms"); + assert_eq!(elapsed_text(Duration::from_millis(999)), "999 ms"); + assert_eq!(elapsed_text(Duration::from_millis(1_234)), "1.23 s"); + assert_eq!(elapsed_text(Duration::from_secs(1)), "1.00 s"); + assert_eq!(elapsed_text(Duration::from_secs(60)), "1m 0s"); + assert_eq!(elapsed_text(Duration::from_secs(125)), "2m 5s"); + let page = PageState { + row_count: 2, + start_ordinal: 0, + filtered: false, + elapsed: Duration::from_millis(5), + }; + assert_eq!(page_range_label(&page, &RowTotal::Exact(2)), "Rows 1 – 2 of 2 · 5 ms"); + } + + #[test] + fn empty_pages_keep_their_fetch_time() { + let mut page = PageState { + row_count: 0, + start_ordinal: 0, + filtered: false, + elapsed: std::time::Duration::from_millis(5), + }; + assert_eq!(page_range_label(&page, &RowTotal::Exact(0)), "No rows · 5 ms"); + page.filtered = true; + assert_eq!( + page_range_label(&page, &RowTotal::Unknown), + "No rows match the filter · 5 ms" + ); + page.start_ordinal = 100; + assert_eq!( + page_range_label(&page, &RowTotal::Unknown), + "No rows on this page · 5 ms" + ); + } + #[test] fn first_page_label() { assert_eq!(label(0, 100, &RowTotal::Unknown), "Rows 1 – 100"); diff --git a/linux/crates/app/src/ui/browse_tab/page_reply.rs b/linux/crates/app/src/ui/browse_tab/page_reply.rs index 3d52cf6980..08d5f6d5d3 100644 --- a/linux/crates/app/src/ui/browse_tab/page_reply.rs +++ b/linux/crates/app/src/ui/browse_tab/page_reply.rs @@ -4,21 +4,17 @@ use tablepro_core::meta::PagePosition; use super::browse_pager::PageEdges; -/// A page as the server returned it, the row identity cells still after -/// the visible ones. #[derive(Debug, Clone)] pub(crate) struct PageReply { pub position: PagePosition, pub result: QueryResult, pub layout: PageLayout, pub edges: PageEdges, - /// The table pages by key or heap address, so its last page reads - /// back from its end. pub seeks: bool, + pub elapsed: std::time::Duration, } impl PageReply { - /// `None` when the page starts at a key or at the table's end. pub fn offset(&self) -> Option { match self.position { PagePosition::First => Some(0), @@ -30,10 +26,8 @@ impl PageReply { | PagePosition::Resume(_) => None, } } -} -impl From for PageReply { - fn from(read: PageRead) -> Self { + pub fn new(read: PageRead, elapsed: std::time::Duration) -> Self { Self { position: read.position, result: read.result, @@ -44,6 +38,7 @@ impl From for PageReply { next: read.next, }, seeks: matches!(read.mode, PagingMode::Keyset | PagingMode::CtidWindow), + elapsed, } } } diff --git a/linux/crates/app/src/ui/browse_tab/page_state.rs b/linux/crates/app/src/ui/browse_tab/page_state.rs index aa171fe30c..78f728a8bc 100644 --- a/linux/crates/app/src/ui/browse_tab/page_state.rs +++ b/linux/crates/app/src/ui/browse_tab/page_state.rs @@ -1,10 +1,7 @@ -/// What the tab knows of the page on screen. Its rows are the grid's: -/// the grid's store holds the only copy. #[derive(Debug, Clone)] pub(crate) struct PageState { pub row_count: usize, - /// How many rows of the table come before the page. pub start_ordinal: u64, - /// The page was read under a filter. pub filtered: bool, + pub elapsed: std::time::Duration, } diff --git a/linux/crates/app/src/ui/browse_tab/pager_bar.rs b/linux/crates/app/src/ui/browse_tab/pager_bar.rs index 5e19a53d64..7a0c71dbd7 100644 --- a/linux/crates/app/src/ui/browse_tab/pager_bar.rs +++ b/linux/crates/app/src/ui/browse_tab/pager_bar.rs @@ -314,6 +314,7 @@ mod tests { fn page(start_ordinal: u64, row_count: usize) -> PageState { PageState { + elapsed: std::time::Duration::from_millis(5), row_count, start_ordinal, filtered: false, @@ -526,11 +527,11 @@ mod tests { bar.show_total(&pager, Some(&page(0, 5)), &RowTotal::Exact(5)); - assert_eq!(bar.imp().paginator_label.label(), "Rows 1 – 5 of 5"); + assert_eq!(bar.imp().paginator_label.label(), "Rows 1 – 5 of 5 · 5 ms"); assert_eq!( crate::ui::a11y::announced_in(&bar), [( - "Rows 1 – 5 of 5".to_owned(), + "Rows 1 – 5 of 5 · 5 ms".to_owned(), gtk::AccessibleAnnouncementPriority::Medium )], "a page turn is said once" diff --git a/linux/crates/app/src/ui/browse_tab/tests/load.rs b/linux/crates/app/src/ui/browse_tab/tests/load.rs index e281dfc373..80e55d318d 100644 --- a/linux/crates/app/src/ui/browse_tab/tests/load.rs +++ b/linux/crates/app/src/ui/browse_tab/tests/load.rs @@ -66,6 +66,7 @@ fn refresh_keeps_grid_visible_and_sets_tab_loading() { }); let harness = Harness::open(script, []); wait_until(WAIT, || harness.shown() == text(&["before"])).expect("the first page"); + let elapsed = harness.elapsed(); let loading = loading_log(&harness); harness.tab().send(PagingInput::Refresh); @@ -73,9 +74,14 @@ fn refresh_keeps_grid_visible_and_sets_tab_loading() { assert_eq!(harness.visible_page().as_deref(), Some("grid")); assert_eq!(harness.shown(), text(&["before"]), "the refresh blanked the rows"); assert!(harness.tab().is_loading()); + assert_eq!(harness.elapsed(), elapsed, "a refresh changed the old page's time"); wait_until(WAIT, || harness.shown() == text(&["after"])).expect("the refreshed page"); assert!(!harness.tab().is_loading()); assert_eq!(*loading.borrow(), [true, false]); + assert!( + harness.elapsed() >= Duration::from_millis(300), + "the new page kept the old time" + ); } #[gtk4::test] @@ -89,6 +95,7 @@ fn failed_refresh_keeps_rows_and_reveals_stale_banner() { })); let harness = Harness::open(script, []); wait_until(WAIT, || harness.shown() == text(&["kept"])).expect("the first page"); + let elapsed = harness.elapsed(); let counters = harness.connection.counters(); harness.tab().send(PagingInput::Refresh); @@ -96,6 +103,7 @@ fn failed_refresh_keeps_rows_and_reveals_stale_banner() { assert_eq!(CallCounters::get(&counters.query_bound), 2); assert_eq!(harness.shown(), text(&["kept"]), "the failed refresh dropped the rows"); + assert_eq!(harness.elapsed(), elapsed, "a failed refresh replaced the page's time"); assert_eq!(harness.visible_page().as_deref(), Some("grid")); assert!(!harness.tab().is_loading()); let tooltip = banner(&harness).tooltip_text().map(|text| text.to_string()); diff --git a/linux/crates/app/src/ui/browse_tab/tests/mod.rs b/linux/crates/app/src/ui/browse_tab/tests/mod.rs index 37b1183146..bd806d6088 100644 --- a/linux/crates/app/src/ui/browse_tab/tests/mod.rs +++ b/linux/crates/app/src/ui/browse_tab/tests/mod.rs @@ -217,6 +217,18 @@ impl Harness { .collect() } + pub(super) fn elapsed(&self) -> Duration { + use gtk4::subclass::prelude::ObjectSubclassIsExt; + self.tab() + .imp() + .model + .borrow() + .as_ref() + .and_then(|model| model.page.as_ref()) + .expect("a loaded page") + .elapsed + } + /// The saved rows the grid holds for the page on screen. pub(super) fn saved_rows(&self) -> Vec { use gtk4::subclass::prelude::ObjectSubclassIsExt; @@ -579,10 +591,16 @@ fn stale_page_reply_ignored() { harness.tab().send(PagingInput::FilterApplied(not_null_name())); wait_until(WAIT, || harness.shown() == text(&["filtered"])).expect("the filtered page"); + let elapsed = harness.elapsed(); std::thread::sleep(Duration::from_millis(500)); drain_main_context(); assert_eq!(CallCounters::get(&counters.query_bound), 2); + assert_eq!( + harness.elapsed(), + elapsed, + "a stale reply changed the displayed page's time" + ); assert_eq!( harness.shown(), text(&["filtered"]), @@ -1537,6 +1555,38 @@ fn a_dotted_field_of_a_document_neither_sorts_nor_takes_an_edit() { assert_eq!(harness.tracker.pending_count(), 0); } +#[gtk4::test] +fn the_paginator_says_how_long_the_page_took() { + use gtk4::subclass::prelude::ObjectSubclassIsExt; + + let mut script = serving_table(); + script.query_bound.always(FakeReply::Late { + after: Duration::from_millis(20), + outcome: Ok(rows(&["Ada", "Grace"])), + }); + let harness = Harness::open(script, []); + wait_until(WAIT, || harness.shown() == text(&["Ada", "Grace"])).expect("the page"); + let label = harness.tab().imp().pager_bar.imp().paginator_label.get(); + + assert!(harness.elapsed() >= Duration::from_millis(20)); + let text = label.label(); + let (_, elapsed) = text.split_once(" · ").expect("the paginator includes a duration"); + assert!(!elapsed.is_empty()); +} + +#[gtk4::test] +fn an_empty_page_also_shows_its_fetch_time() { + use gtk4::subclass::prelude::ObjectSubclassIsExt; + + let mut script = serving_table(); + script.query_bound.always(FakeReply::ok(rows(&[]))); + let harness = Harness::open(script, []); + wait_until(WAIT, || harness.visible_page().as_deref() == Some("grid")).expect("the empty page"); + + let label = harness.tab().imp().pager_bar.imp().paginator_label.label(); + assert!(label.starts_with("No rows · "), "{label}"); +} + #[gtk4::test] fn the_bottom_bar_offers_the_column_chooser() { use gtk4::subclass::prelude::ObjectSubclassIsExt; diff --git a/linux/crates/app/src/ui/browse_tab/tests/total.rs b/linux/crates/app/src/ui/browse_tab/tests/total.rs index 90fc76daff..e71f3d4cf0 100644 --- a/linux/crates/app/src/ui/browse_tab/tests/total.rs +++ b/linux/crates/app/src/ui/browse_tab/tests/total.rs @@ -15,7 +15,12 @@ use crate::services::change_origins::ChangeOrigins; use crate::test_support::{LogLines, drain_main_context, wait_until}; fn paginator(harness: &Harness) -> String { - harness.tab().imp().pager_bar.imp().paginator_label.label().to_string() + let label = harness.tab().imp().pager_bar.imp().paginator_label.label(); + // These tests pin row totals independently of how long the read takes. + label + .split_once(" · ") + .map_or(label.as_str(), |(range, _)| range) + .to_owned() } fn count_button(harness: &Harness) -> gtk4::Button { diff --git a/linux/crates/app/src/ui/workspace/mod.rs b/linux/crates/app/src/ui/workspace/mod.rs index 97905d18c9..1546b9b017 100644 --- a/linux/crates/app/src/ui/workspace/mod.rs +++ b/linux/crates/app/src/ui/workspace/mod.rs @@ -1330,10 +1330,6 @@ impl WorkspaceModel { } } - #[expect( - clippy::too_many_lines, - reason = "Each workspace input dispatches to its own handler" - )] fn update(&mut self, msg: WorkspaceInput) { match msg { WorkspaceInput::HealthChanged(health) => self.refresh_health_banner(&health),