cache all page 60s
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-11 10:45:25 +02:00
parent 2f35b9bdbd
commit 136ad0ecf4
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
8 changed files with 196 additions and 1 deletions

183
Cargo.lock generated
View file

@ -271,6 +271,23 @@ version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
[[package]]
name = "async-trait"
version = "0.1.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.13",
]
[[package]]
name = "async_once"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ce4f10ea3abcd6617873bae9f91d1c5332b4a778bd9ce34d0cd517474c1de82"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -353,6 +370,44 @@ dependencies = [
"bytes", "bytes",
] ]
[[package]]
name = "cached"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e5877db5d1af7fae60d06b5db9430b68056a69b3582a0be8e3691e87654aeb6"
dependencies = [
"async-trait",
"async_once",
"cached_proc_macro",
"cached_proc_macro_types",
"futures",
"hashbrown 0.13.2",
"instant",
"lazy_static",
"once_cell",
"thiserror",
"tokio",
]
[[package]]
name = "cached_proc_macro"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e10ca87c81aaa3a949dbbe2b5e6c2c45dbc94ba4897e45ea31ff9ec5087be3dc"
dependencies = [
"cached_proc_macro_types",
"darling",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "cached_proc_macro_types"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.79" version = "1.0.79"
@ -424,6 +479,41 @@ dependencies = [
"nom", "nom",
] ]
[[package]]
name = "darling"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn 1.0.109",
]
[[package]]
name = "darling_macro"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
dependencies = [
"darling_core",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "derive_more" name = "derive_more"
version = "0.99.17" version = "0.99.17"
@ -462,6 +552,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"actix-files", "actix-files",
"actix-web", "actix-web",
"cached",
"glob", "glob",
"latex2mathml", "latex2mathml",
"markdown", "markdown",
@ -497,12 +588,42 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "futures"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]] [[package]]
name = "futures-core" name = "futures-core"
version = "0.3.28" version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
[[package]]
name = "futures-io"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
[[package]] [[package]]
name = "futures-sink" name = "futures-sink"
version = "0.3.28" version = "0.3.28"
@ -522,6 +643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-sink",
"futures-task", "futures-task",
"pin-project-lite", "pin-project-lite",
"pin-utils", "pin-utils",
@ -579,6 +701,12 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hashbrown"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.3.3" version = "0.3.3"
@ -626,6 +754,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.3.0" version = "0.3.0"
@ -643,7 +777,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"hashbrown", "hashbrown 0.12.3",
]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
] ]
[[package]] [[package]]
@ -1202,6 +1345,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.109" version = "1.0.109"
@ -1224,6 +1373,26 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "thiserror"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.13",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.20" version = "0.3.20"
@ -1280,9 +1449,21 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
"signal-hook-registry", "signal-hook-registry",
"socket2", "socket2",
"tokio-macros",
"windows-sys", "windows-sys",
] ]
[[package]]
name = "tokio-macros"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.13",
]
[[package]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.7" version = "0.7.7"

View file

@ -12,6 +12,7 @@ license = "AGPL-3.0-or-later"
[dependencies] [dependencies]
actix-web = "4" actix-web = "4"
actix-files = "0.6" actix-files = "0.6"
cached = "0.42.0"
ramhorns = "0.14.0" ramhorns = "0.14.0"
toml = "0.7.3" toml = "0.7.3"
serde = { version = "1.0.159", features = ["derive"] } serde = { version = "1.0.159", features = ["derive"] }

View file

@ -1,5 +1,6 @@
use crate::{config::Config, template::Infos}; use crate::{config::Config, template::Infos};
use actix_web::{dev::ConnectionInfo, get, routes, web, HttpRequest, HttpResponse, Responder}; use actix_web::{dev::ConnectionInfo, get, routes, web, HttpRequest, HttpResponse, Responder};
use cached::proc_macro::once;
use ramhorns::Content; use ramhorns::Content;
#[routes] #[routes]
@ -19,6 +20,7 @@ struct SecurityTemplate {
url: String, url: String,
} }
#[once(time = 60)]
fn get_security(config: Config, info: ConnectionInfo) -> String { fn get_security(config: Config, info: ConnectionInfo) -> String {
config.tmpl.render( config.tmpl.render(
"security.txt", "security.txt",
@ -46,6 +48,7 @@ pub async fn robots() -> impl Responder {
HttpResponse::Ok().body(get_robots()) HttpResponse::Ok().body(get_robots())
} }
#[once(time = 60)]
fn get_robots() -> String { fn get_robots() -> String {
// TODO, see https://www.robotstxt.org/orig.html // TODO, see https://www.robotstxt.org/orig.html
"User-agent: * Allow: /".to_string() "User-agent: * Allow: /".to_string()

View file

@ -1,5 +1,6 @@
use crate::{config::Config, template::Infos}; use crate::{config::Config, template::Infos};
use actix_web::{get, web, HttpResponse, Responder}; use actix_web::{get, web, HttpResponse, Responder};
use cached::proc_macro::once;
use ramhorns::Content; use ramhorns::Content;
#[get("/contrib")] #[get("/contrib")]
@ -10,6 +11,7 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
#[derive(Content)] #[derive(Content)]
struct PortfolioTemplate {} struct PortfolioTemplate {}
#[once(time = 60)]
pub fn get_page(config: Config) -> std::string::String { pub fn get_page(config: Config) -> std::string::String {
config.tmpl.render( config.tmpl.render(
"contrib.html", "contrib.html",

View file

@ -1,4 +1,5 @@
use actix_web::{get, web, HttpResponse, Responder}; use actix_web::{get, web, HttpResponse, Responder};
use cached::proc_macro::once;
use ramhorns::Content; use ramhorns::Content;
use crate::{config::Config, template::Infos}; use crate::{config::Config, template::Infos};
@ -11,6 +12,7 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
#[derive(Content)] #[derive(Content)]
struct IndexTemplate {} struct IndexTemplate {}
#[once(time = 60)]
pub fn get_page(config: Config) -> std::string::String { pub fn get_page(config: Config) -> std::string::String {
config.tmpl.render( config.tmpl.render(
"index.html", "index.html",

View file

@ -1,4 +1,5 @@
use actix_web::{get, web, HttpResponse, Responder}; use actix_web::{get, web, HttpResponse, Responder};
use cached::proc_macro::once;
use ramhorns::Content; use ramhorns::Content;
use crate::{config::Config, template::Infos}; use crate::{config::Config, template::Infos};
@ -11,6 +12,7 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
#[derive(Content)] #[derive(Content)]
struct NetworksTemplate {} struct NetworksTemplate {}
#[once(time = 60)]
pub fn get_page(config: Config) -> std::string::String { pub fn get_page(config: Config) -> std::string::String {
config.tmpl.render( config.tmpl.render(
"networks.html", "networks.html",

View file

@ -1,4 +1,5 @@
use actix_web::{web, HttpResponse, Responder}; use actix_web::{web, HttpResponse, Responder};
use cached::proc_macro::once;
use ramhorns::Content; use ramhorns::Content;
use crate::{config::Config, template::Infos}; use crate::{config::Config, template::Infos};
@ -10,6 +11,7 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
#[derive(Content)] #[derive(Content)]
struct Error404Template {} struct Error404Template {}
#[once(time = 60)]
pub fn get_page(config: Config) -> std::string::String { pub fn get_page(config: Config) -> std::string::String {
config config
.tmpl .tmpl

View file

@ -1,4 +1,5 @@
use actix_web::{get, web, HttpResponse, Responder}; use actix_web::{get, web, HttpResponse, Responder};
use cached::proc_macro::once;
use glob::glob; use glob::glob;
use ramhorns::Content; use ramhorns::Content;
@ -19,6 +20,7 @@ struct PortfolioTemplate {
univ_content: String, univ_content: String,
} }
#[once(time = 60)]
pub fn get_page(config: Config) -> std::string::String { pub fn get_page(config: Config) -> std::string::String {
let projects_dir = "data/projects"; let projects_dir = "data/projects";
let ext = ".md"; let ext = ".md";