Skip to content

Commit

Permalink
Flatten perf improvements: gzip response and parallelize sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
agersant committed Aug 10, 2024
1 parent 4112c7d commit d492afc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ thiserror = "1.0.62"
tokio = { version = "1.39", features = ["macros", "rt-multi-thread"] }
tokio-util = { version = "0.7.11", features = ["io"] }
toml = "0.8.19"
tower-http = { version = "0.5.2", features = ["fs"] }
tower-http = { version = "0.5.2", features = ["compression-gzip", "fs"] }
trie-rs = { version = "0.4.2", features = ["serde"] }
unicase = "2.7.0"
ureq = { version = "2.10.0", default-features = false, features = ["tls"] }
Expand Down
3 changes: 2 additions & 1 deletion src/app/index/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
};

use lasso2::{Rodeo, RodeoReader};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use tinyvec::TinyVec;
use trie_rs::{Trie, TrieBuilder};
Expand Down Expand Up @@ -112,7 +113,7 @@ impl Browser {
})
.collect::<Vec<_>>();

files.sort_by(|a, b| {
files.par_sort_by(|a, b| {
let a = UniCase::new(a.as_os_str().to_string_lossy());
let b = UniCase::new(b.as_os_str().to_string_lossy());
a.cmp(&b)
Expand Down
4 changes: 3 additions & 1 deletion src/server/axum/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use axum_extra::TypedHeader;
use axum_range::{KnownSize, Ranged};
use base64::{prelude::BASE64_STANDARD_NO_PAD, Engine};
use percent_encoding::percent_decode_str;
use tower_http::{compression::CompressionLayer, CompressionLevel};

use crate::{
app::{config, ddns, index, lastfm, playlist, scanner, settings, thumbnail, user, vfs, App},
Expand Down Expand Up @@ -56,7 +57,6 @@ pub fn router() -> Router<App> {
.route("/playlist/:name", put(put_playlist))
.route("/playlist/:name", get(get_playlist))
.route("/playlist/:name", delete(delete_playlist))
.route("/audio/*path", get(get_audio))
.route("/thumbnail/*path", get(get_thumbnail))
.route("/lastfm/now_playing/*path", put(put_lastfm_now_playing))
.route("/lastfm/scrobble/*path", post(post_lastfm_scrobble))
Expand All @@ -70,7 +70,9 @@ pub fn router() -> Router<App> {
.route("/random/", get(get_random))
.route("/recent/", get(get_recent))
.route("/search/", get(get_search_root))
.layer(CompressionLayer::new().quality(CompressionLevel::Fastest))
.layer(DefaultBodyLimit::max(10 * 1024 * 1024)) // 10MB
.route("/audio/*path", get(get_audio))
}

async fn get_version() -> Json<dto::Version> {
Expand Down

0 comments on commit d492afc

Please sign in to comment.