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
7 changes: 3 additions & 4 deletions romm-tui/src/tui/app/rom_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ impl super::App {

/// Paint from disk cache when possible, then queue a network refresh only when needed.
///
/// - Valid cache hit (`expected_count` matches): paint and skip fetch.
/// - Complete but stale: paint immediately, keep `[Loading...]`, queue fetch.
/// - Valid or stale complete cache hit: paint immediately, keep `[Loading...]`, queue fetch.
/// - Miss: clear only when needed, queue fetch when `expected > 0`.
pub(in crate::tui::app) fn apply_selection_rom_load(
&mut self,
Expand Down Expand Up @@ -99,10 +98,10 @@ impl super::App {
if let AppScreen::LibraryBrowse(ref mut lib) = self.screen {
if let Some(list) = list {
lib.set_roms(list);
lib.set_rom_loading(false);
lib.set_rom_loading(true);
}
}
self.cancel_primary_rom_load();
self.queue_primary_rom_load(key, req, expected, context);
}
PaintKind::Stale => {
let list = key
Expand Down
17 changes: 11 additions & 6 deletions romm-tui/src/tui/app/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ async fn list_move_to_zero_rom_selection_does_not_queue_deferred_load() {
}

#[tokio::test]
async fn list_move_with_complete_cache_keeps_roms_visible() {
async fn list_move_with_complete_cache_paints_and_queues_refresh() {
let mut app = app_with_library(vec![platform(9101, "NES", 1), platform(9102, "SNES", 1)]);
let list = RomList {
items: vec![rom_fixture()],
Expand All @@ -445,14 +445,19 @@ async fn list_move_with_complete_cache_keeps_roms_visible() {
"cached console must paint immediately without blanking the pane"
);
assert_eq!(lib.roms.as_ref().map(|r| r.items.len()), Some(1));
assert!(!lib.rom_loading, "valid cache hit must not stay in loading");
assert!(
lib.rom_loading,
"valid cache hit should keep [Loading...] until refresh completes"
);
}
_ => panic!("expected library browse"),
}
assert!(
app.deferred_load_roms.is_none(),
"valid cache hit must not queue a network fetch"
);
let Some((key, _, expected, context, _)) = &app.deferred_load_roms else {
panic!("valid cache hit should queue a background refresh");
};
assert_eq!(key, &Some(RomCacheKey::Platform(9102)));
assert_eq!(expected, &1);
assert_eq!(context, &"list_move_down");
}

#[tokio::test]
Expand Down
29 changes: 16 additions & 13 deletions romm-tui/src/tui/app/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@ impl App {
};

if let Some(ref k) = key {
let mut painted_valid_cache = false;
if let Some(cached) = self.rom_cache.get_valid(k, expected) {
if let AppScreen::LibraryBrowse(ref mut lib) = self.screen {
if super::rom_load::primary_rom_load_result_matches_selection(lib, &key) {
lib.set_roms(cached.clone());
lib.set_rom_loading(false);
lib.set_rom_loading(expected > 0);
painted_valid_cache = true;
tracing::debug!(
"rom-list-render context={} latency_ms={} (cache_hit)",
context,
Expand All @@ -191,21 +193,22 @@ impl App {
);
}
}
return;
}
// Stale-complete: paint immediately so the pane is never blank during debounce/fetch.
if let Some(stale) = self.rom_cache.get_complete(k) {
if let AppScreen::LibraryBrowse(ref mut lib) = self.screen {
if super::rom_load::primary_rom_load_result_matches_selection(lib, &key) {
if lib.roms.is_none() {
lib.set_roms(stale.clone());
if !painted_valid_cache {
if let Some(stale) = self.rom_cache.get_complete(k) {
if let AppScreen::LibraryBrowse(ref mut lib) = self.screen {
if super::rom_load::primary_rom_load_result_matches_selection(lib, &key) {
if lib.roms.is_none() {
lib.set_roms(stale.clone());
}
lib.set_rom_loading(expected > 0);
tracing::debug!(
"rom-list-render context={} latency_ms={} (stale_complete)",
context,
started.elapsed().as_millis()
);
}
lib.set_rom_loading(expected > 0);
tracing::debug!(
"rom-list-render context={} latency_ms={} (stale_complete)",
context,
started.elapsed().as_millis()
);
}
}
}
Expand Down
Loading