treewide: general cleanup

Finally had the time to clean up after myself. Does a bunch of things,
without breakage as far as I'm aware. I've removed around 20 unnecessary
clones, and simplified the architechture a little bit. 

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I4d22337b997a3bf5b0593e6068cd1bd86a6a6964
This commit is contained in:
raf 2026-02-27 21:27:57 +03:00
commit a1357b2501
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
6 changed files with 87 additions and 86 deletions

View file

@ -56,18 +56,34 @@ impl RateLimiter {
}
pub async fn acquire(&self, platform: &str) -> Result<()> {
let config = {
let (rate, burst) = {
let inner = self.inner.lock().await;
inner.config.clone()
};
let (rate, burst) = match platform.to_lowercase().as_str() {
"modrinth" => (config.modrinth_requests_per_min, config.modrinth_burst),
"curseforge" => {
(config.curseforge_requests_per_min, config.curseforge_burst)
},
"github" => (config.github_requests_per_min, config.github_burst),
_ => (config.default_requests_per_min, config.default_burst),
match platform.to_lowercase().as_str() {
"modrinth" => {
(
inner.config.modrinth_requests_per_min,
inner.config.modrinth_burst,
)
},
"curseforge" => {
(
inner.config.curseforge_requests_per_min,
inner.config.curseforge_burst,
)
},
"github" => {
(
inner.config.github_requests_per_min,
inner.config.github_burst,
)
},
_ => {
(
inner.config.default_requests_per_min,
inner.config.default_burst,
)
},
}
};
let interval = Duration::from_secs(60) / rate.max(1);
@ -76,7 +92,7 @@ impl RateLimiter {
let mut inner = self.inner.lock().await;
let now = Instant::now();
let platform_requests =
inner.requests.entry(platform.to_string()).or_default();
inner.requests.entry(platform.to_owned()).or_default();
platform_requests
.retain(|t| now.duration_since(*t) < Duration::from_secs(60));