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:
1 parent
4efc2f3968
commit
6584b2f92f
7 files changed
+318
-86
No files matched your search
@@ -8,7 +8,7 @@ use rune::{Color, El, col, el, row, text};
|
||||
|
||||
use crate::app::App;
|
||||
use crate::format;
|
||||
use crate::history::{Outcome, QueueCategory, Timeline};
|
||||
use crate::history::{Outcome, QueueCategory, Summary};
|
||||
use crate::screens::review;
|
||||
use crate::ui::{self, Paint, body, heading};
|
||||
|
||||
@@ -34,11 +34,10 @@ fn outcome_color(p: Paint, outcome: Outcome) -> Color {
|
||||
}
|
||||
|
||||
pub fn view(app: &App, p: Paint) -> El {
|
||||
let filtered: Vec<(usize, &Timeline)> = app
|
||||
let filtered: Vec<&Summary> = app
|
||||
.games
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, g)| app.filter.is_none_or(|f| g.category() == f))
|
||||
.filter(|g| app.filter.is_none_or(|f| g.category() == f))
|
||||
.collect();
|
||||
|
||||
// The scroll bar gets its own strip at the end, clear of the cards.
|
||||
@@ -64,7 +63,7 @@ pub fn view(app: &App, p: Paint) -> El {
|
||||
"Pick another queue above.",
|
||||
));
|
||||
} else {
|
||||
for (index, game) in filtered {
|
||||
for (index, game) in filtered.iter().enumerate() {
|
||||
list = list.child(game_card(app, p, game, index));
|
||||
}
|
||||
}
|
||||
@@ -104,7 +103,7 @@ pub fn view(app: &App, p: Paint) -> El {
|
||||
.color(p.t.text),
|
||||
)
|
||||
.child(
|
||||
text(format!("{} recordings", app.games.len()))
|
||||
text(count_label(app))
|
||||
.key("count")
|
||||
.font(body(11.5))
|
||||
.color(p.muted()),
|
||||
@@ -127,6 +126,18 @@ pub fn view(app: &App, p: Paint) -> El {
|
||||
)
|
||||
}
|
||||
|
||||
/// The line under the title: how many recordings there are, and how many have been read.
|
||||
///
|
||||
/// The list reads a page at a time, so the two differ while it is filling up.
|
||||
fn count_label(app: &App) -> String {
|
||||
let total = app.games_paths.len().max(app.games.len());
|
||||
if app.more_games() {
|
||||
format!("{} recordings · {} loaded", total, app.games.len())
|
||||
} else {
|
||||
format!("{total} recordings")
|
||||
}
|
||||
}
|
||||
|
||||
fn empty(p: Paint, title: &str, detail: &str) -> El {
|
||||
col()
|
||||
.key("empty")
|
||||
@@ -148,9 +159,10 @@ fn empty(p: Paint, title: &str, detail: &str) -> El {
|
||||
)
|
||||
}
|
||||
|
||||
fn game_card(app: &App, p: Paint, game: &Timeline, index: usize) -> El {
|
||||
fn game_card(app: &App, p: Paint, game: &Summary, index: usize) -> El {
|
||||
let outcome = game.outcome();
|
||||
let ink = outcome_color(p, outcome);
|
||||
let id = game.recording_id.clone();
|
||||
let champion = game.champion().unwrap_or_else(|| "Unknown champion".into());
|
||||
let duration = game.duration_secs.max(0) as f64;
|
||||
let lp = game.lp_change();
|
||||
@@ -223,7 +235,7 @@ fn game_card(app: &App, p: Paint, game: &Timeline, index: usize) -> El {
|
||||
.shadow(8.0, 24.0, p.t.shadow_soft)
|
||||
.hover(p.t.hover)
|
||||
.press(p.t.press)
|
||||
.on_press(move |app: &mut App| review::open(app, index))
|
||||
.on_press(move |app: &mut App| review::open(app, &id))
|
||||
.child(
|
||||
col().key("card").w_full().child(banner).child(
|
||||
row()
|
||||
|
||||
+35
-15
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user