Skip to content

Commit

Permalink
chore: inline the function retrive_sort_from_paginate
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Dec 1, 2023
1 parent 9bc5df2 commit 8fd7bb1
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,6 @@ impl_axum_webpage! {
status = |search| search.status,
}

fn retrive_sort_from_paginate(query: &str) -> String {
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[?&]sort=([^&]+)").unwrap());
let cap = RE.captures(query).unwrap();
cap.get(1)
.map_or("relevance".to_string(), |v| v.as_str().to_string())
}

pub(crate) async fn search_handler(
mut conn: DbConnection,
Extension(pool): Extension<Pool>,
Expand Down Expand Up @@ -586,7 +579,13 @@ pub(crate) async fn search_handler(
);
return Err(AxumNope::NoResults);
}
sort_by = retrive_sort_from_paginate(&query_params);

static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[?&]sort=([^&]+)").unwrap());
let cap = RE.captures(&query_params).unwrap();
sort_by = cap
.get(1)
.map_or("relevance".to_string(), |v| v.as_str().to_string());

get_search_results(&mut conn, &config, &query_params).await?
} else if !query.is_empty() {
let query_params: String = form_urlencoded::Serializer::new(String::new())
Expand Down

0 comments on commit 8fd7bb1

Please sign in to comment.