Skip to content

Commit

Permalink
Fix search by artist and other minor fixes
Browse files Browse the repository at this point in the history
- Allow fuzzy search for artist name
- Increase pool size
- Let handle_missing_track run in background
  • Loading branch information
tranxuanthang committed Oct 14, 2024
1 parent 4d6f7dd commit dd7626c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ lazy_static! {
pub fn init_db(path: &PathBuf) -> Result<Pool<SqliteConnectionManager>> {
let manager = SqliteConnectionManager::file(path);
let pool = r2d2::Pool::builder()
.max_size(15)
.max_size(30)
.build(manager)?;

let mut conn = pool.get()?;
Expand Down
2 changes: 1 addition & 1 deletion server/src/repositories/track_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub fn get_tracks_by_keyword(
Some(track_name) => {
let mut result = format!("(name_lower : \"{}\")", track_name).to_owned();
if let Some(artist_name) = artist_name {
result.push_str(format!("AND (artist_name_lower : \"{}\")", artist_name).as_ref());
result.push_str(format!("AND (artist_name_lower : {})", artist_name).as_ref());
}
if let Some(album_name) = album_name {
result.push_str(format!("AND (album_name_lower : \"{}\")", album_name).as_ref());
Expand Down
8 changes: 6 additions & 2 deletions server/src/routes/get_lyrics_by_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use validator::Validate;
use anyhow::Result;
use crossbeam_queue::ArrayQueue;

#[derive(Validate, Deserialize)]
#[derive(Clone, Validate, Deserialize)]
pub struct QueryParams {
#[validate(length(min = 1, message = "cannot be empty"))]
track_name: String,
Expand Down Expand Up @@ -42,7 +42,11 @@ pub async fn route(Query(params): Query<QueryParams>, State(state): State<Arc<Ap
}

// If not found, handle missing track logic
handle_missing_track(&params, &state).await;
let params_clone = params.clone();
let state_clone = state.clone();
tokio::spawn(async move {
handle_missing_track(&params_clone, &state_clone).await;
});

// Retry fetching the track without the album name
if let Some(track) = fetch_track_without_album(&params, &state).await? {
Expand Down

0 comments on commit dd7626c

Please sign in to comment.