Skip to content

Commit

Permalink
Fix open cache file blocking worker thread
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Oct 6, 2023
1 parent 54cc7eb commit d5da1fa
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/route/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ async fn hath(
if let Some(file) = data
.cache_manager
.get_file(&info)
.map(|f| async move { NamedFile::open_async(f?).await.ok() })
.flatten()
.then(|f| async move { tokio::task::spawn_blocking(|| NamedFile::open(f?).ok()).await.ok().flatten() })
.await
{
let cache_header = CacheControl(vec![CacheDirective::Public, CacheDirective::MaxAge(31536000)])
Expand Down Expand Up @@ -184,7 +183,7 @@ async fn hath(
builder.insert_header(CacheControl(vec![CacheDirective::Public, CacheDirective::MaxAge(31536000)]));
builder.body(SizedStream::new(
file_size,
stream! { // TODO bandwidth limit
stream! {
let mut file = File::open(temp_path.as_ref()).await.unwrap();
let mut read_off = 0;
let mut write_off = *rx.borrow();
Expand Down

0 comments on commit d5da1fa

Please sign in to comment.