make update_needed check lazy (#706)
This commit is contained in:
parent
edda1b741a
commit
2672f78dda
3 changed files with 34 additions and 9 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -89,6 +89,7 @@ dependencies = [
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"eyre",
|
"eyre",
|
||||||
"fs-err",
|
"fs-err",
|
||||||
|
"futures-util",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"interim",
|
"interim",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
@ -737,6 +738,17 @@ dependencies = [
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.11.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-sink"
|
name = "futures-sink"
|
||||||
version = "0.3.24"
|
version = "0.3.24"
|
||||||
|
@ -756,6 +768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90"
|
checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-macro",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
|
|
@ -73,6 +73,7 @@ rpassword = "7.0"
|
||||||
semver = "1.0.14"
|
semver = "1.0.14"
|
||||||
runtime-format = "0.1.2"
|
runtime-format = "0.1.2"
|
||||||
tiny-bip39 = "1"
|
tiny-bip39 = "1"
|
||||||
|
futures-util = "0.3"
|
||||||
|
|
||||||
# from tui
|
# from tui
|
||||||
bitflags = "1.3"
|
bitflags = "1.3"
|
||||||
|
|
|
@ -16,6 +16,7 @@ use crossterm::{
|
||||||
execute, terminal,
|
execute, terminal,
|
||||||
};
|
};
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
use futures_util::FutureExt;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
|
@ -393,7 +394,8 @@ pub async fn history(
|
||||||
// Put the cursor at the end of the query by default
|
// Put the cursor at the end of the query by default
|
||||||
input.end();
|
input.end();
|
||||||
|
|
||||||
let update_needed = settings.needs_update().await;
|
let update_needed = settings.needs_update().fuse();
|
||||||
|
tokio::pin!(update_needed);
|
||||||
|
|
||||||
let mut app = State {
|
let mut app = State {
|
||||||
history_count: db.history_count().await?,
|
history_count: db.history_count().await?,
|
||||||
|
@ -405,7 +407,7 @@ pub async fn history(
|
||||||
} else {
|
} else {
|
||||||
settings.filter_mode
|
settings.filter_mode
|
||||||
},
|
},
|
||||||
update_needed,
|
update_needed: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut results = app.query_results(settings.search_mode, db).await?;
|
let mut results = app.query_results(settings.search_mode, db).await?;
|
||||||
|
@ -427,15 +429,24 @@ pub async fn history(
|
||||||
let initial_input = app.input.as_str().to_owned();
|
let initial_input = app.input.as_str().to_owned();
|
||||||
let initial_filter_mode = app.filter_mode;
|
let initial_filter_mode = app.filter_mode;
|
||||||
|
|
||||||
if event::poll(Duration::from_millis(250))? {
|
let event_ready = tokio::task::spawn_blocking(|| event::poll(Duration::from_millis(250)));
|
||||||
loop {
|
|
||||||
if let Some(i) = app.handle_input(settings, &event::read()?, results.len()) {
|
tokio::select! {
|
||||||
break 'render i;
|
event_ready = event_ready => {
|
||||||
}
|
if event_ready?? {
|
||||||
if !event::poll(Duration::ZERO)? {
|
loop {
|
||||||
break;
|
if let Some(i) = app.handle_input(settings, &event::read()?, results.len()) {
|
||||||
|
break 'render i;
|
||||||
|
}
|
||||||
|
if !event::poll(Duration::ZERO)? {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
update_needed = &mut update_needed => {
|
||||||
|
app.update_needed = update_needed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if initial_input != app.input.as_str() || initial_filter_mode != app.filter_mode {
|
if initial_input != app.input.as_str() || initial_filter_mode != app.filter_mode {
|
||||||
|
|
Loading…
Reference in a new issue