Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Commit

Permalink
⚡️ Cache the first few search results
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Jul 19, 2021
1 parent c1a92bd commit 0597ff5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blitz-dashboard"
version = "0.14.0"
version = "0.14.1"
authors = ["Pavel Perestoronin <[email protected]>"]
edition = "2018"
resolver = "2"
Expand Down
6 changes: 6 additions & 0 deletions src/wargaming/cache/account/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions src/web/routes/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@ pub enum Response {
pub async fn get(
query: String,
account_search_cache: &State<AccountSearchCache>,
account_info_cache: &State<AccountInfoCache>,
tracking_code: &State<TrackingCode>,
) -> crate::web::result::Result<Response> {
clear_user();
Expand All @@ -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)
Expand Down

0 comments on commit 0597ff5

Please sign in to comment.