Don't persist read search client across reqs (#5277)
This commit is contained in:
committed by
GitHub
parent
345ada27c0
commit
f81f951814
@@ -18,7 +18,6 @@ use crate::background_task::update_versions;
|
|||||||
use crate::database::{PgPool, ReadOnlyPgPool};
|
use crate::database::{PgPool, ReadOnlyPgPool};
|
||||||
use crate::queue::billing::{index_billing, index_subscriptions};
|
use crate::queue::billing::{index_billing, index_subscriptions};
|
||||||
use crate::queue::moderation::AutomatedModerationQueue;
|
use crate::queue::moderation::AutomatedModerationQueue;
|
||||||
use crate::search::MeilisearchReadClient;
|
|
||||||
use crate::util::anrok;
|
use crate::util::anrok;
|
||||||
use crate::util::archon::ArchonClient;
|
use crate::util::archon::ArchonClient;
|
||||||
use crate::util::env::{parse_strings_from_var, parse_var};
|
use crate::util::env::{parse_strings_from_var, parse_var};
|
||||||
@@ -68,7 +67,6 @@ pub struct LabrinthConfig {
|
|||||||
pub email_queue: web::Data<EmailQueue>,
|
pub email_queue: web::Data<EmailQueue>,
|
||||||
pub archon_client: web::Data<ArchonClient>,
|
pub archon_client: web::Data<ArchonClient>,
|
||||||
pub gotenberg_client: GotenbergClient,
|
pub gotenberg_client: GotenbergClient,
|
||||||
pub search_read_client: web::Data<MeilisearchReadClient>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@@ -275,11 +273,6 @@ pub fn app_setup(
|
|||||||
file_host,
|
file_host,
|
||||||
scheduler: Arc::new(scheduler),
|
scheduler: Arc::new(scheduler),
|
||||||
ip_salt,
|
ip_salt,
|
||||||
search_read_client: web::Data::new(
|
|
||||||
search_config.make_loadbalanced_read_client().expect(
|
|
||||||
"Failed to make Meilisearch client for read operations",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
search_config,
|
search_config,
|
||||||
session_queue,
|
session_queue,
|
||||||
payouts_queue: web::Data::new(PayoutsQueue::new()),
|
payouts_queue: web::Data::new(PayoutsQueue::new()),
|
||||||
@@ -331,7 +324,6 @@ pub fn app_config(
|
|||||||
.app_data(labrinth_config.archon_client.clone())
|
.app_data(labrinth_config.archon_client.clone())
|
||||||
.app_data(web::Data::new(labrinth_config.stripe_client.clone()))
|
.app_data(web::Data::new(labrinth_config.stripe_client.clone()))
|
||||||
.app_data(web::Data::new(labrinth_config.anrok_client.clone()))
|
.app_data(web::Data::new(labrinth_config.anrok_client.clone()))
|
||||||
.app_data(labrinth_config.search_read_client.clone())
|
|
||||||
.app_data(labrinth_config.rate_limiter.clone())
|
.app_data(labrinth_config.rate_limiter.clone())
|
||||||
.configure({
|
.configure({
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ use crate::queue::moderation::AutomatedModerationQueue;
|
|||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
use crate::routes::v3::projects::ProjectIds;
|
use crate::routes::v3::projects::ProjectIds;
|
||||||
use crate::routes::{ApiError, v2_reroute, v3};
|
use crate::routes::{ApiError, v2_reroute, v3};
|
||||||
use crate::search::{
|
use crate::search::{SearchConfig, SearchError, search_for_project};
|
||||||
MeilisearchReadClient, SearchConfig, SearchError, search_for_project,
|
|
||||||
};
|
|
||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -56,7 +54,6 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
|||||||
pub async fn project_search(
|
pub async fn project_search(
|
||||||
web::Query(info): web::Query<SearchRequest>,
|
web::Query(info): web::Query<SearchRequest>,
|
||||||
config: web::Data<SearchConfig>,
|
config: web::Data<SearchConfig>,
|
||||||
read_client: web::Data<MeilisearchReadClient>,
|
|
||||||
) -> Result<HttpResponse, SearchError> {
|
) -> Result<HttpResponse, SearchError> {
|
||||||
// Search now uses loader_fields instead of explicit 'client_side' and 'server_side' fields
|
// Search now uses loader_fields instead of explicit 'client_side' and 'server_side' fields
|
||||||
// While the backend for this has changed, it doesnt affect much
|
// While the backend for this has changed, it doesnt affect much
|
||||||
@@ -102,7 +99,7 @@ pub async fn project_search(
|
|||||||
..info
|
..info
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = search_for_project(&info, &config, &read_client).await?;
|
let results = search_for_project(&info, &config).await?;
|
||||||
|
|
||||||
let results = LegacySearchResults::from(results);
|
let results = LegacySearchResults::from(results);
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ use crate::queue::moderation::AutomatedModerationQueue;
|
|||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use crate::search::indexing::remove_documents;
|
use crate::search::indexing::remove_documents;
|
||||||
use crate::search::{
|
use crate::search::{SearchConfig, SearchError, search_for_project};
|
||||||
MeilisearchReadClient, SearchConfig, SearchError, search_for_project,
|
|
||||||
};
|
|
||||||
use crate::util::img;
|
use crate::util::img;
|
||||||
use crate::util::img::{delete_old_images, upload_image_optimized};
|
use crate::util::img::{delete_old_images, upload_image_optimized};
|
||||||
use crate::util::routes::read_limited_from_payload;
|
use crate::util::routes::read_limited_from_payload;
|
||||||
@@ -1039,9 +1037,8 @@ pub async fn edit_project_categories(
|
|||||||
pub async fn project_search(
|
pub async fn project_search(
|
||||||
web::Query(info): web::Query<SearchRequest>,
|
web::Query(info): web::Query<SearchRequest>,
|
||||||
config: web::Data<SearchConfig>,
|
config: web::Data<SearchConfig>,
|
||||||
read_client: web::Data<MeilisearchReadClient>,
|
|
||||||
) -> Result<HttpResponse, SearchError> {
|
) -> Result<HttpResponse, SearchError> {
|
||||||
let results = search_for_project(&info, &config, &read_client).await?;
|
let results = search_for_project(&info, &config).await?;
|
||||||
|
|
||||||
// TODO: add this back
|
// TODO: add this back
|
||||||
// let results = ReturnSearchResults {
|
// let results = ReturnSearchResults {
|
||||||
|
|||||||
@@ -283,7 +283,6 @@ pub fn get_sort_index(
|
|||||||
pub async fn search_for_project(
|
pub async fn search_for_project(
|
||||||
info: &SearchRequest,
|
info: &SearchRequest,
|
||||||
config: &SearchConfig,
|
config: &SearchConfig,
|
||||||
client: &MeilisearchReadClient,
|
|
||||||
) -> Result<SearchResults, SearchError> {
|
) -> Result<SearchResults, SearchError> {
|
||||||
let offset: usize = info.offset.as_deref().unwrap_or("0").parse()?;
|
let offset: usize = info.offset.as_deref().unwrap_or("0").parse()?;
|
||||||
let index = info.index.as_deref().unwrap_or("relevance");
|
let index = info.index.as_deref().unwrap_or("relevance");
|
||||||
@@ -295,6 +294,7 @@ pub async fn search_for_project(
|
|||||||
.min(100);
|
.min(100);
|
||||||
|
|
||||||
let sort = get_sort_index(config, index)?;
|
let sort = get_sort_index(config, index)?;
|
||||||
|
let client = config.make_loadbalanced_read_client()?;
|
||||||
let meilisearch_index = client.get_index(sort.0).await?;
|
let meilisearch_index = client.get_index(sort.0).await?;
|
||||||
|
|
||||||
let mut filter_string = String::new();
|
let mut filter_string = String::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user