From 0597ff5f789a49be6cdd97df44c6dddfeb2643ae Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Mon, 19 Jul 2021 23:29:57 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Cache=20the=20first=20few?= =?UTF-8?q?=20search=20results?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/wargaming/cache/account/info.rs | 6 ++++++ src/web/routes/search.rs | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ebc1abd3..0ed6ad9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,7 +244,7 @@ dependencies = [ [[package]] name = "blitz-dashboard" -version = "0.14.0" +version = "0.14.1" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index fee8daa0..096feccb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blitz-dashboard" -version = "0.14.0" +version = "0.14.1" authors = ["Pavel Perestoronin "] edition = "2018" resolver = "2" diff --git a/src/wargaming/cache/account/info.rs b/src/wargaming/cache/account/info.rs index fd5dfbc1..3e3c7a32 100644 --- a/src/wargaming/cache/account/info.rs +++ b/src/wargaming/cache/account/info.rs @@ -38,4 +38,10 @@ impl AccountInfoCache { .map_err(|error| anyhow::anyhow!(error)) .with_context(|| format!("failed to access the cache for account #{}", account_id)) } + + pub async fn insert(&self, account_info: AccountInfo) { + self.cache + .insert(account_info.general.id, Arc::new(account_info)) + .await; + } } diff --git a/src/web/routes/search.rs b/src/web/routes/search.rs index 230d5708..3aae44ba 100644 --- a/src/web/routes/search.rs +++ b/src/web/routes/search.rs @@ -5,6 +5,7 @@ use rocket::response::Redirect; use rocket::{Responder, State}; use crate::logging::clear_user; +use crate::wargaming::cache::account::info::AccountInfoCache; use crate::wargaming::cache::account::search::AccountSearchCache; use crate::web::partials::{account_search, datetime, footer, headers}; use crate::web::routes::player::get_account_url; @@ -22,6 +23,7 @@ pub enum Response { pub async fn get( query: String, account_search_cache: &State, + account_info_cache: &State, tracking_code: &State, ) -> crate::web::result::Result { clear_user(); @@ -38,6 +40,9 @@ pub async fn get( .last_battle_time .cmp(&left.general.last_battle_time) }); + for account in &accounts[..3] { + account_info_cache.insert(account.clone()).await; + } let markup = html! { (DOCTYPE)