Skip to content

Commit

Permalink
make update_needed check lazy (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellie authored Feb 10, 2023
1 parent edda1b7 commit 2672f78
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 20 additions & 9 deletions src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crossterm::{
execute, terminal,
};
use eyre::Result;
use futures_util::FutureExt;
use semver::Version;
use unicode_width::UnicodeWidthStr;

Expand Down Expand Up @@ -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?,
Expand All @@ -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?;
Expand All @@ -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 {
Expand Down

0 comments on commit 2672f78

Please sign in to comment.