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",
|
||||
"eyre",
|
||||
"fs-err",
|
||||
"futures-util",
|
||||
"indicatif",
|
||||
"interim",
|
||||
"itertools",
|
||||
|
@ -737,6 +738,17 @@ dependencies = [
|
|||
"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]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.24"
|
||||
|
@ -756,6 +768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-macro",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
|
|
|
@ -73,6 +73,7 @@ rpassword = "7.0"
|
|||
semver = "1.0.14"
|
||||
runtime-format = "0.1.2"
|
||||
tiny-bip39 = "1"
|
||||
futures-util = "0.3"
|
||||
|
||||
# from tui
|
||||
bitflags = "1.3"
|
||||
|
|
|
@ -16,6 +16,7 @@ use crossterm::{
|
|||
execute, terminal,
|
||||
};
|
||||
use eyre::Result;
|
||||
use futures_util::FutureExt;
|
||||
use semver::Version;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
|
@ -393,7 +394,8 @@ pub async fn history(
|
|||
// Put the cursor at the end of the query by default
|
||||
input.end();
|
||||
|
||||
let update_needed = settings.needs_update().await;
|
||||
let update_needed = settings.needs_update().fuse();
|
||||
tokio::pin!(update_needed);
|
||||
|
||||
let mut app = State {
|
||||
history_count: db.history_count().await?,
|
||||
|
@ -405,7 +407,7 @@ pub async fn history(
|
|||
} else {
|
||||
settings.filter_mode
|
||||
},
|
||||
update_needed,
|
||||
update_needed: None,
|
||||
};
|
||||
|
||||
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_filter_mode = app.filter_mode;
|
||||
|
||||
if event::poll(Duration::from_millis(250))? {
|
||||
loop {
|
||||
if let Some(i) = app.handle_input(settings, &event::read()?, results.len()) {
|
||||
break 'render i;
|
||||
}
|
||||
if !event::poll(Duration::ZERO)? {
|
||||
break;
|
||||
let event_ready = tokio::task::spawn_blocking(|| event::poll(Duration::from_millis(250)));
|
||||
|
||||
tokio::select! {
|
||||
event_ready = event_ready => {
|
||||
if event_ready?? {
|
||||
loop {
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue