From 6206d0ea58bc3c6b874c62639e01f3aa0093eda9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemens=20Sch=C3=B6lhorn?= Date: Thu, 6 Apr 2023 22:06:29 +0200 Subject: [PATCH] Use std RwLock instead of the tokio one tokio recommends to use the std synchronization primitives if the locked value is just data instead of a shared resource. --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9620ae4..eaa65bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{net::SocketAddr, path::{Path, PathBuf}, ffi::{OsStr, OsString}, fs::File, io::{BufReader, Seek, Cursor, BufRead}, env::args_os, os::unix::prelude::OsStrExt, cmp::Reverse, sync::Arc, collections::HashMap}; +use std::{net::SocketAddr, path::{Path, PathBuf}, ffi::{OsStr, OsString}, fs::File, io::{BufReader, Seek, Cursor, BufRead}, env::args_os, os::unix::prelude::OsStrExt, cmp::Reverse, sync::{Arc, RwLock}, collections::HashMap}; use anyhow::{Context, Result, anyhow}; use axum::{Router, routing::{get, post}, response::{IntoResponse, Redirect}, http::{StatusCode, header}, extract::{self, State}, Form, handler::Handler}; @@ -10,7 +10,7 @@ use error::AppError; use exif::Exif; use image::{imageops::FilterType, DynamicImage}; use serde::{Serialize, Deserialize}; -use tokio::{task, sync::RwLock}; +use tokio::task; use tower_http::{trace::{self, TraceLayer}, compression::CompressionLayer}; use tracing::Level; use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt}; @@ -195,7 +195,7 @@ async fn converted_image( .ok(); let cached_buffer = if let Some(image_modified) = image_modified { image_cache - .read().await + .read().unwrap() .get(image_name) .filter(|(cache_modified, _)| *cache_modified == image_modified) .map(|(_, image_buffer)| image_buffer) @@ -216,7 +216,7 @@ async fn converted_image( if let Some(image_modified) = image_modified { tracing::debug!("Add {:?} ({}k) to cache", image_name, image_buffer.len() / 1024); image_cache - .write().await + .write().unwrap() .insert(image_name.to_owned(), (image_modified, image_buffer.clone())); }