Limit number of profiles in search results
This commit is contained in:
parent
f9689807e3
commit
28fad8986c
4 changed files with 25 additions and 4 deletions
|
@ -69,6 +69,7 @@ async fn search_profiles(
|
|||
db_client: &impl GenericClient,
|
||||
username: String,
|
||||
mut instance: Option<String>,
|
||||
limit: i64,
|
||||
) -> Result<Vec<DbActorProfile>, HttpError> {
|
||||
if let Some(ref actor_host) = instance {
|
||||
if actor_host == &config.instance().host() {
|
||||
|
@ -76,7 +77,12 @@ async fn search_profiles(
|
|||
instance = None;
|
||||
};
|
||||
};
|
||||
let mut profiles = search_profile(db_client, &username, instance.as_ref()).await?;
|
||||
let mut profiles = search_profile(
|
||||
db_client,
|
||||
&username,
|
||||
instance.as_ref(),
|
||||
limit,
|
||||
).await?;
|
||||
if profiles.is_empty() && instance.is_some() {
|
||||
let actor_address = ActorAddress {
|
||||
username: username,
|
||||
|
@ -125,12 +131,19 @@ pub async fn search(
|
|||
current_user: &User,
|
||||
db_client: &mut impl GenericClient,
|
||||
search_query: &str,
|
||||
limit: i64,
|
||||
) -> Result<SearchResults, HttpError> {
|
||||
let mut profiles = vec![];
|
||||
let mut posts = vec![];
|
||||
match parse_search_query(search_query) {
|
||||
SearchQuery::ProfileQuery(username, instance) => {
|
||||
profiles = search_profiles(config, db_client, username, instance).await?;
|
||||
profiles = search_profiles(
|
||||
config,
|
||||
db_client,
|
||||
username,
|
||||
instance,
|
||||
limit,
|
||||
).await?;
|
||||
},
|
||||
SearchQuery::Url(url) => {
|
||||
let maybe_post = search_post(config, db_client, url).await?;
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
/// https://docs.joinmastodon.org/methods/search/
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::mastodon_api::accounts::types::Account;
|
||||
use crate::mastodon_api::statuses::types::Status;
|
||||
|
||||
/// https://docs.joinmastodon.org/methods/search/
|
||||
fn default_limit() -> i64 { 20 }
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SearchQueryParams {
|
||||
pub q: String,
|
||||
|
||||
#[serde(default = "default_limit")]
|
||||
pub limit: i64,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
|
|
@ -23,6 +23,7 @@ async fn search_view(
|
|||
¤t_user,
|
||||
db_client,
|
||||
query_params.q.trim(),
|
||||
query_params.limit,
|
||||
).await?;
|
||||
Ok(HttpResponse::Ok().json(results))
|
||||
}
|
||||
|
|
|
@ -344,6 +344,7 @@ pub async fn search_profile(
|
|||
db_client: &impl GenericClient,
|
||||
username: &str,
|
||||
instance: Option<&String>,
|
||||
limit: i64,
|
||||
) -> Result<Vec<DbActorProfile>, DatabaseError> {
|
||||
let db_search_query = match instance {
|
||||
Some(instance) => {
|
||||
|
@ -360,8 +361,9 @@ pub async fn search_profile(
|
|||
SELECT actor_profile
|
||||
FROM actor_profile
|
||||
WHERE acct ILIKE $1
|
||||
LIMIT $2
|
||||
",
|
||||
&[&db_search_query],
|
||||
&[&db_search_query, &limit],
|
||||
).await?;
|
||||
let profiles: Vec<DbActorProfile> = rows.iter()
|
||||
.map(|row| row.try_get("actor_profile"))
|
||||
|
|
Loading…
Reference in a new issue