From f81f9518149a83dc9fc27522f2dfdfa3b69d3343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Talbot?= <108630700+fetchfern@users.noreply.github.com> Date: Mon, 2 Feb 2026 09:09:00 -0500 Subject: [PATCH] Don't persist read search client across reqs (#5277) --- apps/labrinth/src/lib.rs | 8 -------- apps/labrinth/src/routes/v2/projects.rs | 7 ++----- apps/labrinth/src/routes/v3/projects.rs | 7 ++----- apps/labrinth/src/search/mod.rs | 2 +- 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/apps/labrinth/src/lib.rs b/apps/labrinth/src/lib.rs index 851798756..5a687c574 100644 --- a/apps/labrinth/src/lib.rs +++ b/apps/labrinth/src/lib.rs @@ -18,7 +18,6 @@ use crate::background_task::update_versions; use crate::database::{PgPool, ReadOnlyPgPool}; use crate::queue::billing::{index_billing, index_subscriptions}; use crate::queue::moderation::AutomatedModerationQueue; -use crate::search::MeilisearchReadClient; use crate::util::anrok; use crate::util::archon::ArchonClient; use crate::util::env::{parse_strings_from_var, parse_var}; @@ -68,7 +67,6 @@ pub struct LabrinthConfig { pub email_queue: web::Data, pub archon_client: web::Data, pub gotenberg_client: GotenbergClient, - pub search_read_client: web::Data, } #[allow(clippy::too_many_arguments)] @@ -275,11 +273,6 @@ pub fn app_setup( file_host, scheduler: Arc::new(scheduler), 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, session_queue, payouts_queue: web::Data::new(PayoutsQueue::new()), @@ -331,7 +324,6 @@ pub fn app_config( .app_data(labrinth_config.archon_client.clone()) .app_data(web::Data::new(labrinth_config.stripe_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()) .configure({ #[cfg(target_os = "linux")] diff --git a/apps/labrinth/src/routes/v2/projects.rs b/apps/labrinth/src/routes/v2/projects.rs index 91c3f0b21..5750cd6fd 100644 --- a/apps/labrinth/src/routes/v2/projects.rs +++ b/apps/labrinth/src/routes/v2/projects.rs @@ -14,9 +14,7 @@ use crate::queue::moderation::AutomatedModerationQueue; use crate::queue::session::AuthQueue; use crate::routes::v3::projects::ProjectIds; use crate::routes::{ApiError, v2_reroute, v3}; -use crate::search::{ - MeilisearchReadClient, SearchConfig, SearchError, search_for_project, -}; +use crate::search::{SearchConfig, SearchError, search_for_project}; use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -56,7 +54,6 @@ pub fn config(cfg: &mut web::ServiceConfig) { pub async fn project_search( web::Query(info): web::Query, config: web::Data, - read_client: web::Data, ) -> Result { // 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 @@ -102,7 +99,7 @@ pub async fn project_search( ..info }; - let results = search_for_project(&info, &config, &read_client).await?; + let results = search_for_project(&info, &config).await?; let results = LegacySearchResults::from(results); diff --git a/apps/labrinth/src/routes/v3/projects.rs b/apps/labrinth/src/routes/v3/projects.rs index ac6e362a0..60590e8f3 100644 --- a/apps/labrinth/src/routes/v3/projects.rs +++ b/apps/labrinth/src/routes/v3/projects.rs @@ -28,9 +28,7 @@ use crate::queue::moderation::AutomatedModerationQueue; use crate::queue::session::AuthQueue; use crate::routes::ApiError; use crate::search::indexing::remove_documents; -use crate::search::{ - MeilisearchReadClient, SearchConfig, SearchError, search_for_project, -}; +use crate::search::{SearchConfig, SearchError, search_for_project}; use crate::util::img; use crate::util::img::{delete_old_images, upload_image_optimized}; use crate::util::routes::read_limited_from_payload; @@ -1039,9 +1037,8 @@ pub async fn edit_project_categories( pub async fn project_search( web::Query(info): web::Query, config: web::Data, - read_client: web::Data, ) -> Result { - let results = search_for_project(&info, &config, &read_client).await?; + let results = search_for_project(&info, &config).await?; // TODO: add this back // let results = ReturnSearchResults { diff --git a/apps/labrinth/src/search/mod.rs b/apps/labrinth/src/search/mod.rs index b8f349650..e64aa0707 100644 --- a/apps/labrinth/src/search/mod.rs +++ b/apps/labrinth/src/search/mod.rs @@ -283,7 +283,6 @@ pub fn get_sort_index( pub async fn search_for_project( info: &SearchRequest, config: &SearchConfig, - client: &MeilisearchReadClient, ) -> Result { let offset: usize = info.offset.as_deref().unwrap_or("0").parse()?; let index = info.index.as_deref().unwrap_or("relevance"); @@ -295,6 +294,7 @@ pub async fn search_for_project( .min(100); let sort = get_sort_index(config, index)?; + let client = config.make_loadbalanced_read_client()?; let meilisearch_index = client.get_index(sort.0).await?; let mut filter_string = String::new();