Compare commits
No commits in common. "e8e3302f8250059fa47e620e35306c777dd1480d" and "030a38ded4ccb22c9626f92b37460fa990615341" have entirely different histories.
e8e3302f82
...
030a38ded4
|
@ -246,7 +246,7 @@ checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "breeze"
|
name = "breeze"
|
||||||
version = "0.2.3"
|
version = "0.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "breeze"
|
name = "breeze"
|
||||||
version = "0.2.3"
|
version = "0.2.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
26
src/cache.rs
26
src/cache.rs
|
@ -178,10 +178,9 @@ impl Cache {
|
||||||
// drop the reference so we don't deadlock
|
// drop the reference so we don't deadlock
|
||||||
drop(e);
|
drop(e);
|
||||||
|
|
||||||
// remove it
|
// remove it and say we never had it
|
||||||
self.remove(key);
|
self.remove(key);
|
||||||
|
|
||||||
// and say we never had it
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,29 +230,14 @@ impl Cache {
|
||||||
// If we don't do this it'll be a LOT of system api calls
|
// If we don't do this it'll be a LOT of system api calls
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
|
|
||||||
// Collect a list of all the expired keys
|
// Drop every expired entry
|
||||||
// If we fail to compare the times, it gets added to the list anyways
|
// If we fail to compare the times, we drop the entry
|
||||||
let expired: Vec<_> = self
|
self.map.retain(|_, e| {
|
||||||
.map
|
|
||||||
.par_iter()
|
|
||||||
.filter_map(|e| {
|
|
||||||
let elapsed = now.duration_since(e.last_used()).unwrap_or(Duration::MAX);
|
let elapsed = now.duration_since(e.last_used()).unwrap_or(Duration::MAX);
|
||||||
let is_expired = elapsed >= e.lifetime;
|
let is_expired = elapsed >= e.lifetime;
|
||||||
|
|
||||||
if is_expired {
|
!is_expired
|
||||||
Some(e.key().clone())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect();
|
|
||||||
|
|
||||||
// If we have any, lock the map and drop all of them
|
|
||||||
if !expired.is_empty() {
|
|
||||||
// Use a retain call, should be less locks that way
|
|
||||||
// (instead of many remove calls)
|
|
||||||
self.map.retain(|k, _| !expired.contains(k))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,17 +8,14 @@ pub async fn index(State(engine): State<Arc<crate::engine::Engine>>) -> String {
|
||||||
|
|
||||||
let motd = engine.cfg.motd.clone();
|
let motd = engine.cfg.motd.clone();
|
||||||
|
|
||||||
motd.replace("%version%", env!("CARGO_PKG_VERSION"))
|
motd
|
||||||
|
.replace("%version%", env!("CARGO_PKG_VERSION"))
|
||||||
.replace("%uplcount%", &count.to_string())
|
.replace("%uplcount%", &count.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn robots_txt() -> &'static str {
|
pub async fn robots_txt() -> &'static str {
|
||||||
/// robots.txt that tells web crawlers not to list uploads
|
/// robots.txt that tells web crawlers not to list uploads
|
||||||
const ROBOTS_TXT: &str = concat!(
|
const ROBOTS_TXT: &str = concat!("User-Agent: *\n", "Disallow: /p/*\n", "Allow: /\n");
|
||||||
"User-Agent: *\n",
|
|
||||||
"Disallow: /p/*\n",
|
|
||||||
"Allow: /\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
ROBOTS_TXT
|
ROBOTS_TXT
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use std::{ffi::OsStr, path::PathBuf, sync::Arc};
|
use std::{
|
||||||
|
ffi::OsStr, path::PathBuf, sync::Arc
|
||||||
|
};
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
body::Body,
|
body::Body,
|
||||||
|
|
Loading…
Reference in New Issue