Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions linux/changelog.d/4119.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A table tab's paginator says how long the page took to read.
4 changes: 3 additions & 1 deletion linux/crates/app/src/ui/browse_tab/data_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -187,6 +187,7 @@ impl BrowseModel {
layout,
edges,
seeks,
elapsed,
} = reply;
self.pager.land(offset, position, edges, seeks);
let QueryResult { columns, rows, .. } = result;
Expand All @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions linux/crates/app/src/ui/browse_tab/data_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BrowseCommand>),
LinkChanged(LinkGeneration),
/// The table's definition changed. The catalog has already dropped
/// its columns, so they are read again before the page.
SchemaChanged,
}
5 changes: 3 additions & 2 deletions linux/crates/app/src/ui/browse_tab/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand All @@ -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 }))));
}
});
}
Expand Down
74 changes: 72 additions & 2 deletions linux/crates/app/src/ui/browse_tab/page_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand Down
11 changes: 3 additions & 8 deletions linux/crates/app/src/ui/browse_tab/page_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64> {
match self.position {
PagePosition::First => Some(0),
Expand All @@ -30,10 +26,8 @@ impl PageReply {
| PagePosition::Resume(_) => None,
}
}
}

impl From<PageRead> for PageReply {
fn from(read: PageRead) -> Self {
pub fn new(read: PageRead, elapsed: std::time::Duration) -> Self {
Self {
position: read.position,
result: read.result,
Expand All @@ -44,6 +38,7 @@ impl From<PageRead> for PageReply {
next: read.next,
},
seeks: matches!(read.mode, PagingMode::Keyset | PagingMode::CtidWindow),
elapsed,
}
}
}
5 changes: 1 addition & 4 deletions linux/crates/app/src/ui/browse_tab/page_state.rs
Original file line number Diff line number Diff line change
@@ -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,
}
5 changes: 3 additions & 2 deletions linux/crates/app/src/ui/browse_tab/pager_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions linux/crates/app/src/ui/browse_tab/tests/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,22 @@ 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);

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]
Expand All @@ -89,13 +95,15 @@ 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);
wait_until(WAIT, || banner(&harness).is_revealed()).expect("the failed refresh was not shown");

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());
Expand Down
50 changes: 50 additions & 0 deletions linux/crates/app/src/ui/browse_tab/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GridRow> {
use gtk4::subclass::prelude::ObjectSubclassIsExt;
Expand Down Expand Up @@ -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"]),
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion linux/crates/app/src/ui/browse_tab/tests/total.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions linux/crates/app/src/ui/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading