Line optimizations
This commit is contained in:
parent
975c4b1eaf
commit
64f5115d54
1 changed files with 8 additions and 7 deletions
|
|
@ -34,7 +34,7 @@ static DOWN_SPAN: Lazy<Span<'static>> =
|
||||||
static UNKNOWN_SPAN: Lazy<Span<'static>> =
|
static UNKNOWN_SPAN: Lazy<Span<'static>> =
|
||||||
Lazy::new(|| Span::styled("■", Style::default().fg(Color::Yellow)));
|
Lazy::new(|| Span::styled("■", Style::default().fg(Color::Yellow)));
|
||||||
|
|
||||||
static STATUS_LINE_CACHE: OnceLock<RwLock<HashMap<u64, Vec<&'static Span<'static>>>>> = OnceLock::new();
|
static STATUS_LINE_CACHE: OnceLock<RwLock<HashMap<u64, Line<'static>>>> = OnceLock::new();
|
||||||
|
|
||||||
pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut DashboardViewState) {
|
pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut DashboardViewState) {
|
||||||
let available_height = area.height as usize;
|
let available_height = area.height as usize;
|
||||||
|
|
@ -251,18 +251,19 @@ fn get_cached_status_line(status_history: &[MonitorStatus]) -> Line<'static> {
|
||||||
let cache = STATUS_LINE_CACHE.get_or_init(|| RwLock::new(HashMap::new()));
|
let cache = STATUS_LINE_CACHE.get_or_init(|| RwLock::new(HashMap::new()));
|
||||||
{
|
{
|
||||||
let read = cache.read().unwrap();
|
let read = cache.read().unwrap();
|
||||||
if let Some(spans) = read.get(&hash) {
|
if let Some(line) = read.get(&hash) {
|
||||||
return Line::from(spans.iter().map(|&span| span.clone()).collect::<Vec<_>>());
|
return line.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let spans: Vec<&'static Span<'static>> = status_history
|
let spans: Vec<Span<'static>> = status_history
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.take(STATUS_LINE_LENGTH)
|
.take(STATUS_LINE_LENGTH)
|
||||||
.map(|status| get_status_span(status))
|
.map(|status| get_status_span(status).clone())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let new_line = Line::from(spans);
|
||||||
let mut write = cache.write().unwrap();
|
let mut write = cache.write().unwrap();
|
||||||
if write.len() > 1000 {
|
if write.len() > 1000 {
|
||||||
let keys_to_remove: Vec<_> = write.keys().take(250).copied().collect();
|
let keys_to_remove: Vec<_> = write.keys().take(250).copied().collect();
|
||||||
|
|
@ -271,6 +272,6 @@ fn get_cached_status_line(status_history: &[MonitorStatus]) -> Line<'static> {
|
||||||
write.remove(&key);
|
write.remove(&key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write.insert(hash, spans.clone());
|
write.insert(hash, new_line.clone());
|
||||||
Line::from(spans.iter().map(|&span| span.clone()).collect::<Vec<_>>())
|
new_line
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue