cache map list forever

This commit is contained in:
Robin Appelman 2023-11-26 22:07:52 +01:00
commit aab10fad1d
2 changed files with 8 additions and 8 deletions

4
Cargo.lock generated
View file

@ -2111,9 +2111,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.17.1" version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]] [[package]]
name = "opaque-debug" name = "opaque-debug"

View file

@ -59,6 +59,7 @@ struct App {
openid: SteamOpenId, openid: SteamOpenId,
api: String, api: String,
maps: String, maps: String,
map_list: Vec<String>,
pub session_store: MemoryStore, pub session_store: MemoryStore,
} }
@ -90,6 +91,7 @@ async fn main() -> Result<()> {
.expect("no config file or env provided"); .expect("no config file or env provided");
let connection = config.database.connect().await?; let connection = config.database.connect().await?;
let map_list = map_list(&connection).await?.collect();
let session_store = MemoryStore::new(); let session_store = MemoryStore::new();
let state = Arc::new(App { let state = Arc::new(App {
@ -98,6 +100,7 @@ async fn main() -> Result<()> {
.expect("invalid steam login url"), .expect("invalid steam login url"),
api: config.site.api, api: config.site.api,
maps: config.site.maps, maps: config.site.maps,
map_list,
session_store: session_store.clone(), session_store: session_store.clone(),
}); });
@ -194,11 +197,10 @@ async fn index(
) -> Result<Markup> { ) -> Result<Markup> {
let filter = filter.map(|filter| filter.0).unwrap_or_default(); let filter = filter.map(|filter| filter.0).unwrap_or_default();
let demos = ListDemo::list(&app.connection, filter).await?; let demos = ListDemo::list(&app.connection, filter).await?;
let maps: Vec<_> = map_list(&app.connection).await?.collect();
Ok(render( Ok(render(
Index { Index {
demos: &demos, demos: &demos,
maps: &maps, maps: &app.map_list,
api: &app.api, api: &app.api,
}, },
session, session,
@ -345,7 +347,6 @@ async fn uploads(
filter.uploader = Some(uploader.clone()); filter.uploader = Some(uploader.clone());
let demos = ListDemo::list(&app.connection, filter).await?; let demos = ListDemo::list(&app.connection, filter).await?;
let maps: Vec<_> = map_list(&app.connection).await?.collect();
let user = User::get(&app.connection, uploader) let user = User::get(&app.connection, uploader)
.await .await
.map_err(|_| Error::NotFound)?; .map_err(|_| Error::NotFound)?;
@ -353,7 +354,7 @@ async fn uploads(
Uploads { Uploads {
user, user,
demos: &demos, demos: &demos,
maps: &maps, maps: &app.map_list,
api: &app.api, api: &app.api,
}, },
session, session,
@ -371,7 +372,6 @@ async fn profiles(
filter.players.push(profile.clone()); filter.players.push(profile.clone());
let demos = ListDemo::list(&app.connection, filter).await?; let demos = ListDemo::list(&app.connection, filter).await?;
let maps: Vec<_> = map_list(&app.connection).await?.collect();
let user = User::get(&app.connection, profile) let user = User::get(&app.connection, profile)
.await .await
.map_err(|_| Error::NotFound)?; .map_err(|_| Error::NotFound)?;
@ -379,7 +379,7 @@ async fn profiles(
Profile { Profile {
user, user,
demos: &demos, demos: &demos,
maps: &maps, maps: &app.map_list,
api: &app.api, api: &app.api,
}, },
session, session,