Skip to content
Draft
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
8 changes: 8 additions & 0 deletions television/channels/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ impl<P: EntryProcessor> Channel<P> {
self.matcher.tick();
}

/// Refresh cached counts without running the full results pipeline.
///
/// Keeps `result_count()` accurate on ticks where `results()` is skipped.
pub fn update_counts(&mut self) {
self.matcher.update_counts();
}

pub fn results(&mut self, num_entries: u32, offset: u32) -> Vec<Entry> {
self.matcher.tick();

Expand Down Expand Up @@ -581,6 +588,7 @@ impl ChannelKind {
reload() -> (),
find(pattern: &str) -> (),
tick() -> (),
update_counts() -> (),
results(num_entries: u32, offset: u32) -> Vec<Entry>,
get_result(index: u32) -> Option<Entry>,
toggle_selection(entry: &Entry) -> (),
Expand Down
10 changes: 10 additions & 0 deletions television/matcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ where
self.status = self.inner.tick(MATCHER_TICK_TIMEOUT).into();
}

/// Refresh cached counts from the current snapshot.
///
/// Cheap alternative to `results()`: no lock, no per-item work.
/// Requires a prior `tick()` to reflect the latest worker progress.
pub fn update_counts(&mut self) {
let snapshot = self.inner.snapshot();
self.total_item_count = snapshot.item_count();
self.matched_item_count = snapshot.matched_item_count();
}

/// Get an injector that can be used to push items into the fuzzy matcher.
///
/// This can be used at any time to push items into the fuzzy matcher.
Expand Down
11 changes: 7 additions & 4 deletions television/television.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ impl Television {

// Always let the background matcher make progress
self.channel.tick();
self.channel.update_counts();

// When the channel transitions from running to stopped, reset ticks
// to restart the fast-render window. This ensures newly loaded results
Expand All @@ -1160,9 +1161,11 @@ impl Television {
}
self.was_running = running;

// Only run the full results pipeline when the action could
// have changed the results or the visible viewport
if action.affects_results() {
let will_render = self.should_render(action);

// Defer the expensive results pipeline (matcher lock, index
// computation, per-item to_string) to render-eligible ticks.
if will_render {
self.update_results_picker_state();
}

Expand All @@ -1181,7 +1184,7 @@ impl Television {
}
self.ticks += 1;

Ok(if self.should_render(action) {
Ok(if will_render {
Some(Action::Render)
} else {
None
Expand Down
Loading