mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
improve performance of long error list
This commit is contained in:
parent
b62b0a8d8e
commit
538f5db41d
5 changed files with 52 additions and 25 deletions
|
|
@ -28,10 +28,8 @@ impl<'logs> App<'logs> {
|
||||||
.find_lines(move |line| line.request_id == request_id)
|
.find_lines(move |line| line.request_id == request_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_lines(&self) -> impl Iterator<Item = (&'logs str, &'logs JsonError)> + use<'logs> {
|
pub fn error_lines<'a>(&'a self) -> &'a [(&'logs str, JsonError)] {
|
||||||
self.lines.errors().iter().map(|(line_number, error)| {
|
self.lines.errors()
|
||||||
(self.log_file.nth(*line_number).unwrap_or_default(), error)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_count(&self) -> usize {
|
pub fn error_count(&self) -> usize {
|
||||||
|
|
|
||||||
10
src/logs.rs
10
src/logs.rs
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::logfile::{LogLine, LogLineNumber};
|
use crate::logfile::LogLine;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::Error as JsonError;
|
use serde_json::Error as JsonError;
|
||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
|
|
@ -21,14 +21,14 @@ impl From<&usize> for LogIndex {
|
||||||
|
|
||||||
pub struct ParsedLogs<'logfile> {
|
pub struct ParsedLogs<'logfile> {
|
||||||
parsed: Vec<LogLine<'logfile>>,
|
parsed: Vec<LogLine<'logfile>>,
|
||||||
error_lines: Vec<(LogLineNumber, JsonError)>,
|
error_lines: Vec<(&'logfile str, JsonError)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'logfile> ParsedLogs<'logfile> {
|
impl<'logfile> ParsedLogs<'logfile> {
|
||||||
pub fn all(&self) -> &[LogLine<'logfile>] {
|
pub fn all(&self) -> &[LogLine<'logfile>] {
|
||||||
&self.parsed
|
&self.parsed
|
||||||
}
|
}
|
||||||
pub fn errors(&self) -> &[(LogLineNumber, JsonError)] {
|
pub fn errors(&self) -> &[(&'logfile str, JsonError)] {
|
||||||
&self.error_lines
|
&self.error_lines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,8 +48,8 @@ impl<'logfile> ParsedLogs<'logfile> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FromIterator<Result<LogLine<'a>, (LogLineNumber, JsonError)>> for ParsedLogs<'a> {
|
impl<'a> FromIterator<Result<LogLine<'a>, (&'a str, JsonError)>> for ParsedLogs<'a> {
|
||||||
fn from_iter<T: IntoIterator<Item = Result<LogLine<'a>, (LogLineNumber, JsonError)>>>(
|
fn from_iter<T: IntoIterator<Item = Result<LogLine<'a>, (&'a str, JsonError)>>>(
|
||||||
iter: T,
|
iter: T,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let iter = iter.into_iter();
|
let iter = iter.into_iter();
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ fn main() -> MainResult {
|
||||||
|
|
||||||
progress.icr();
|
progress.icr();
|
||||||
|
|
||||||
parsed.map_err(|err| (line_number, err))
|
parsed.map_err(|err| (line, err))
|
||||||
})
|
})
|
||||||
.progress_with_style(progress_style.clone())
|
.progress_with_style(progress_style.clone())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,28 @@
|
||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
use crate::ui::style::TABLE_HEADER_STYLE;
|
use crate::ui::style::TABLE_HEADER_STYLE;
|
||||||
use crate::ui::table::ScrollbarTable;
|
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
|
||||||
use ratatui::layout::Constraint;
|
use ratatui::buffer::Buffer;
|
||||||
|
use ratatui::layout::{Constraint, Rect};
|
||||||
use ratatui::text::Text;
|
use ratatui::text::Text;
|
||||||
use ratatui::widgets::{Cell, Row};
|
use ratatui::widgets::{Cell, Row, StatefulWidget};
|
||||||
|
|
||||||
pub fn error_list<'a>(app: &App<'a>) -> ScrollbarTable<'a> {
|
pub fn error_list<'a>(app: &'a App<'a>) -> ErrorList<'a> {
|
||||||
|
ErrorList {
|
||||||
|
errors: app.error_lines(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ErrorList<'a> {
|
||||||
|
errors: &'a [(&'a str, serde_json::Error)],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StatefulWidget for ErrorList<'_> {
|
||||||
|
type State = ScrollbarTableState;
|
||||||
|
|
||||||
|
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State)
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
let header = [Text::from("Error"), Text::from("Line")]
|
let header = [Text::from("Error"), Text::from("Line")]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(Cell::from)
|
.map(Cell::from)
|
||||||
|
|
@ -14,9 +31,21 @@ pub fn error_list<'a>(app: &App<'a>) -> ScrollbarTable<'a> {
|
||||||
.height(1);
|
.height(1);
|
||||||
|
|
||||||
let widths = [Constraint::Percentage(50), Constraint::Percentage(50)];
|
let widths = [Constraint::Percentage(50), Constraint::Percentage(50)];
|
||||||
ScrollbarTable::new(app.error_lines().map(error_row), widths).header(header)
|
let table = ScrollbarTable::new(
|
||||||
|
self.errors.iter().enumerate().map(|(i, (line, error))| {
|
||||||
|
if i.abs_diff(state.selected()) < 100 {
|
||||||
|
error_row(line, error)
|
||||||
|
} else {
|
||||||
|
Row::new::<[Text; 0]>([])
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
widths,
|
||||||
|
)
|
||||||
|
.header(header);
|
||||||
|
table.render(area, buf, state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_row<'a>((line, err): (&'a str, &'a serde_json::Error)) -> Row<'a> {
|
fn error_row<'a>(line: &'a str, err: &'a serde_json::Error) -> Row<'a> {
|
||||||
Row::new([Text::from(format!("{err}")), Text::from(line)])
|
Row::new([Text::from(format!("{err}")), Text::from(line)])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -638,8 +638,8 @@ impl<'a> UiState<'a> {
|
||||||
(UiState::Errors(state), UiEvent::Copy) => {
|
(UiState::Errors(state), UiEvent::Copy) => {
|
||||||
let raw = app
|
let raw = app
|
||||||
.error_lines()
|
.error_lines()
|
||||||
.nth(state.table_state.selected())
|
.get(state.table_state.selected())
|
||||||
.map(|(line, _)| line)
|
.map(|(line, _)| *line)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
copy_osc(raw);
|
copy_osc(raw);
|
||||||
(false, UiState::Errors(state))
|
(false, UiState::Errors(state))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue