projects
/
valheim_web.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
525a070
)
Use a cached function
author
Greg Burri
<greg.burri@gmail.com>
Mon, 15 Mar 2021 11:42:52 +0000
(12:42 +0100)
committer
Greg Burri
<greg.burri@gmail.com>
Mon, 15 Mar 2021 11:42:52 +0000
(12:42 +0100)
backend/src/main.rs
patch
|
blob
|
history
diff --git
a/backend/src/main.rs
b/backend/src/main.rs
index
84485c2
..
03963c1
100644
(file)
--- a/
backend/src/main.rs
+++ b/
backend/src/main.rs
@@
-7,6
+7,7
@@
use actix_web::{ get, web, Responder, middleware, App, HttpServer };
use askama::Template;
use ron::{ de::from_reader, ser::{ to_string_pretty, PrettyConfig } };
use serde::{ Deserialize, Serialize };
use askama::Template;
use ron::{ de::from_reader, ser::{ to_string_pretty, PrettyConfig } };
use serde::{ Deserialize, Serialize };
+use cached::proc_macro::cached;
mod consts;
mod tests;
mod consts;
mod tests;
@@
-25,11
+26,16
@@
struct MainTemplate {
const VALUE_UNKNOWN: &str = "-";
const VALUE_UNKNOWN: &str = "-";
+#[cached(size = 1, time = 10)]
+fn get_valheim_executable_information_cached(world_path: String) -> Option<valheim_controller::ValheimExe> {
+ valheim_controller::get_valheim_executable_information(&world_path)
+}
+
#[get("/")]
async fn main_page(config_shared: web::Data<Mutex<Config>>) -> impl Responder {
let config = config_shared.lock().unwrap();
#[get("/")]
async fn main_page(config_shared: web::Data<Mutex<Config>>) -> impl Responder {
let config = config_shared.lock().unwrap();
- match
valheim_controller::get_valheim_executable_information(&config.world_path
) {
+ match
get_valheim_executable_information_cached(config.world_path.clone()
) {
Some(info) =>
MainTemplate {
text_status: String::from("Valheim server is up and running :)"),
Some(info) =>
MainTemplate {
text_status: String::from("Valheim server is up and running :)"),