optimizations
This commit is contained in:
parent
64f5115d54
commit
99d4b94e5c
6 changed files with 54 additions and 48 deletions
|
|
@ -30,6 +30,8 @@ use std::{
|
|||
};
|
||||
|
||||
const INITIAL_INTERVAL: u32 = 300;
|
||||
const MAIN_LAYOUT_WITH_SCROLLBAR: [Constraint; 2] = [Constraint::Min(1), Constraint::Length(1)];
|
||||
const MAIN_LAYOUT_WITHOUT_SCROLLBAR: [Constraint; 1] = [Constraint::Min(1)];
|
||||
|
||||
enum FetchResult {
|
||||
Heartbeat(Result<HeartbeatResponse>),
|
||||
|
|
@ -134,12 +136,11 @@ impl App {
|
|||
|
||||
render_header(frame, chunks[0], &self.state);
|
||||
|
||||
let mut main_constraint = Vec::with_capacity(2);
|
||||
main_constraint.push(Constraint::Min(1));
|
||||
|
||||
if self.state.show_vertical_scrollbar(chunks[1].height) {
|
||||
main_constraint.push(Constraint::Length(1));
|
||||
}
|
||||
let main_constraint = if self.state.show_vertical_scrollbar(chunks[1].height) {
|
||||
&MAIN_LAYOUT_WITH_SCROLLBAR[..]
|
||||
} else {
|
||||
&MAIN_LAYOUT_WITHOUT_SCROLLBAR[..]
|
||||
};
|
||||
|
||||
let main_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
|
|
|
|||
|
|
@ -137,11 +137,10 @@ fn render_monitor_table(
|
|||
|
||||
let header = Row::new(header_cells).style(title_style()).height(1);
|
||||
|
||||
let rows: Vec<Row> = monitors
|
||||
.iter()
|
||||
.take(items_to_show)
|
||||
.map(|monitor| create_monitor_item(monitor))
|
||||
.collect();
|
||||
let mut rows: Vec<Row> = Vec::with_capacity(items_to_show);
|
||||
for monitor in monitors.iter().take(items_to_show) {
|
||||
rows.push(create_monitor_item(monitor));
|
||||
}
|
||||
|
||||
let widths = vec![
|
||||
Constraint::Length(3),
|
||||
|
|
@ -256,17 +255,20 @@ fn get_cached_status_line(status_history: &[MonitorStatus]) -> Line<'static> {
|
|||
}
|
||||
}
|
||||
|
||||
let spans: Vec<Span<'static>> = status_history
|
||||
.iter()
|
||||
.rev()
|
||||
.take(STATUS_LINE_LENGTH)
|
||||
.map(|status| get_status_span(status).clone())
|
||||
.collect();
|
||||
let mut spans: Vec<Span<'static>> = Vec::with_capacity(STATUS_LINE_LENGTH);
|
||||
spans.extend(
|
||||
status_history
|
||||
.iter()
|
||||
.rev()
|
||||
.take(STATUS_LINE_LENGTH)
|
||||
.map(|status| get_status_span(status).clone()),
|
||||
);
|
||||
|
||||
let new_line = Line::from(spans);
|
||||
let mut write = cache.write().unwrap();
|
||||
if write.len() > 1000 {
|
||||
let keys_to_remove: Vec<_> = write.keys().take(250).copied().collect();
|
||||
let mut keys_to_remove: Vec<u64> = Vec::with_capacity(250);
|
||||
keys_to_remove.extend(write.keys().take(250).copied());
|
||||
|
||||
for key in keys_to_remove {
|
||||
write.remove(&key);
|
||||
|
|
|
|||
|
|
@ -95,16 +95,12 @@ impl DashboardViewState {
|
|||
}
|
||||
|
||||
fn get_status_history(heartbeats: &[HeartbeatEntry]) -> Vec<MonitorStatus> {
|
||||
let mut history = heartbeats
|
||||
.iter()
|
||||
.rev()
|
||||
.take(100)
|
||||
.map(|h| match h.status {
|
||||
0 => MonitorStatus::Down,
|
||||
1 => MonitorStatus::Up,
|
||||
_ => MonitorStatus::Unknown,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let mut history: Vec<_> = Vec::with_capacity(heartbeats.len());
|
||||
history.extend(heartbeats.iter().rev().take(100).map(|h| match h.status {
|
||||
0 => MonitorStatus::Down,
|
||||
1 => MonitorStatus::Up,
|
||||
_ => MonitorStatus::Unknown,
|
||||
}));
|
||||
|
||||
while history.len() < 100 {
|
||||
history.push(MonitorStatus::Unknown);
|
||||
|
|
@ -142,7 +138,7 @@ fn add_monitor_view_state(group: UnifiedGroupData) -> Vec<MonitorViewState> {
|
|||
|
||||
let name: Cow<'static, str> = match monitor.name {
|
||||
Cow::Borrowed(borrowed) => Cow::Owned(borrowed.to_string()),
|
||||
Cow::Owned(owned) => Cow::Owned(owned)
|
||||
Cow::Owned(owned) => Cow::Owned(owned),
|
||||
};
|
||||
|
||||
MonitorViewState {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue