app: read the history a page at a time and open clips on demand

Every launch parsed all 313 timelines, raw responses and all, which put
2.1 GB of JSON on the heap at startup.

The list now holds `Summary` rows: `history::summaries` parses a file,
keeps the champion, queue, scoreline, LP change and event count, then
drops the timeline. Files are listed by write time, and `poll` reads the
next 20 when the list is scrolled near its end or when the filtered rows
do not fill the screen. Selecting a row hands its id to the review
screen, which reads that one timeline on a thread.

Peak memory over 313 recordings: 165 MB.
This commit is contained in:
vhaudiquet committed 2026-11-16 23:48:58 +01:00
1 parent 4efc2f3968
commit 6584b2f92f
7 files changed
+318 -86

No files matched your search

+35 -15
View File
@@ -8,12 +8,15 @@ use rune::{El, Player, SurfaceFit, Tx, col, el, row, text};
use crate::app::{App, Screen};
use crate::format;
use crate::highlight::{self, Highlight};
use crate::history::{Outcome, Timeline};
use crate::history::{self, Outcome, Timeline};
use crate::ui::{self, Paint, body, heading};
#[derive(Default)]
pub struct Review {
pub game: Option<String>,
/// The opened recording, once its file has been read.
pub game: Option<Timeline>,
/// Set while that file is on its way to the screen.
pub loading: bool,
pub player: Option<Player>,
pub time: f64,
pub duration: f64,
@@ -45,30 +48,41 @@ impl Review {
}
}
/// Open a game in the review screen and load its clip.
pub fn open(app: &mut App, index: usize) {
/// Open a recording in the review screen.
///
/// Only the id travels here: the timeline with its events and raw responses is a large file
/// and stays on disk until a row is opened. It is read on a thread, and `poll` hands it to
/// [`show`] when it arrives.
pub fn open(app: &mut App, recording_id: &str) {
leave(app);
app.screen = Screen::Review;
app.review.loading = true;
let Some(game) = app.games.get(index) else {
return;
};
// Keep the recording id, not the row number: a new recording can re-sort the list.
app.review.game = Some(game.recording_id.clone());
let id = recording_id.to_string();
let (tx, rx) = std::sync::mpsc::channel();
std::thread::spawn(move || {
let _ = tx.send(history::load(&id));
});
app.review_rx = Some(rx);
}
/// Fill the review screen with a timeline that has been read, and load its clip.
pub fn show(app: &mut App, game: Timeline) {
let path = game.video_path();
let highlights = highlight::compute(
game,
&game,
game.summoner().as_deref(),
highlight::Options::default(),
);
let duration = game.duration_secs.max(0) as f64;
app.review.highlights = highlights;
app.review.duration = duration;
app.review.duration = game.duration_secs.max(0) as f64;
let video_file = game.video_file.clone();
app.review.game = Some(game);
let Some(path) = path else {
app.review.error = Some(format!(
"No video file found for this recording ({}).",
game.video_file.as_deref().unwrap_or("unnamed")
video_file.as_deref().unwrap_or("unnamed")
));
return;
};
@@ -82,6 +96,8 @@ pub fn open(app: &mut App, index: usize) {
/// Leave the review screen and stop playback.
pub fn leave(app: &mut App) {
app.review_rx = None;
app.review.loading = false;
app.review.player = None;
app.review.game = None;
app.review.highlights.clear();
@@ -91,7 +107,6 @@ pub fn leave(app: &mut App) {
app.review.export_note = None;
app.review.export = None;
}
/// Called from `poll` while the review screen is up.
pub fn tick(app: &mut App, tx: &mut Tx) -> bool {
let mut changed = false;
@@ -138,10 +153,15 @@ pub fn tick(app: &mut App, tx: &mut Tx) -> bool {
pub fn view(app: &App, p: Paint) -> El {
let Some(game) = app.reviewed() else {
let message = if app.review.loading {
"Opening the recording…"
} else {
"No game selected."
};
return col()
.key("review")
.padding(space::S6)
.child(text("No game selected.").font(body(13.0)).color(p.muted()));
.child(text(message).font(body(13.0)).color(p.muted()));
};
let outcome = game.outcome();
let ink = match outcome {