From 62e1268e0e85a06192e749b0a2a7406a73d1acc1 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Mon, 16 Feb 2026 19:16:03 -0500 Subject: [PATCH 1/3] Add support for dependencies in search --- .../src/search/indexing/local_import.rs | 17 +++++++++++++++++ apps/labrinth/src/search/indexing/mod.rs | 2 ++ apps/labrinth/src/search/mod.rs | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/apps/labrinth/src/search/indexing/local_import.rs b/apps/labrinth/src/search/indexing/local_import.rs index 6c2549fef1..958c0eb293 100644 --- a/apps/labrinth/src/search/indexing/local_import.rs +++ b/apps/labrinth/src/search/indexing/local_import.rs @@ -414,6 +414,7 @@ pub async fn index_local( featured_gallery: featured_gallery.clone(), open_source, color: project.color.map(|x| x as u32), + dependencies: version.dependencies, loader_fields, project_loader_fields: project_loader_fields.clone(), // 'loaders' is aggregate of all versions' loaders @@ -433,6 +434,7 @@ struct PartialVersion { loaders: Vec, project_types: Vec, version_fields: Vec, + dependencies: Vec, } async fn index_versions( @@ -549,6 +551,20 @@ async fn index_versions( .map(|(_, version_fields)| version_fields) .unwrap_or_default(); + let dependencies: Vec = sqlx::query!( + " + SELECT mod_dependency_id as \"mod_dependency_id: DBProjectId\" + FROM dependencies + WHERE dependent_id = $1", + version_id.0 + ) + .fetch_all(pool) + .await? + .iter() + .flat_map(|r| r.mod_dependency_id) + .map(|id| crate::models::ids::ProjectId::from(id).to_string()) + .collect(); + res_versions .entry(*project_id) .or_default() @@ -557,6 +573,7 @@ async fn index_versions( loaders: version_loader_data.loaders, project_types: version_loader_data.project_types, version_fields, + dependencies, }); } } diff --git a/apps/labrinth/src/search/indexing/mod.rs b/apps/labrinth/src/search/indexing/mod.rs index 2da327ce14..557f2d1fcd 100644 --- a/apps/labrinth/src/search/indexing/mod.rs +++ b/apps/labrinth/src/search/indexing/mod.rs @@ -565,6 +565,7 @@ const DEFAULT_DISPLAYED_ATTRIBUTES: &[&str] = &[ "gallery", "featured_gallery", "color", + "dependencies", // Note: loader fields are not here, but are added on as they are needed (so they can be dynamically added depending on which exist). // TODO: remove these- as they should be automatically populated. This is a band-aid fix. "environment", @@ -609,6 +610,7 @@ const DEFAULT_ATTRIBUTES_FOR_FACETING: &[&str] = &[ "project_id", "open_source", "color", + "dependencies", // Note: loader fields are not here, but are added on as they are needed (so they can be dynamically added depending on which exist). // TODO: remove these- as they should be automatically populated. This is a band-aid fix. "environment", diff --git a/apps/labrinth/src/search/mod.rs b/apps/labrinth/src/search/mod.rs index e64aa07071..7e0f5d3ff9 100644 --- a/apps/labrinth/src/search/mod.rs +++ b/apps/labrinth/src/search/mod.rs @@ -216,6 +216,8 @@ pub struct UploadSearchProject { pub open_source: bool, pub color: Option, + pub dependencies: Vec, + // Hidden fields to get the Project model out of the search results. pub loaders: Vec, // Search uses loaders as categories- this is purely for the Project model. pub project_loader_fields: HashMap>, // Aggregation of loader_fields from all versions of the project, allowing for reconstruction of the Project model. @@ -255,6 +257,8 @@ pub struct ResultSearchProject { pub featured_gallery: Option, pub color: Option, + pub dependencies: Vec, + // Hidden fields to get the Project model out of the search results. pub loaders: Vec, // Search uses loaders as categories- this is purely for the Project model. pub project_loader_fields: HashMap>, // Aggregation of loader_fields from all versions of the project, allowing for reconstruction of the Project model. From c14016bc850156efdc7175d947aeaf9c55be87b1 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Mon, 16 Feb 2026 20:28:15 -0500 Subject: [PATCH 2/3] Add dependency slug to project search index --- .../src/search/indexing/local_import.rs | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/labrinth/src/search/indexing/local_import.rs b/apps/labrinth/src/search/indexing/local_import.rs index 958c0eb293..f2712b71d3 100644 --- a/apps/labrinth/src/search/indexing/local_import.rs +++ b/apps/labrinth/src/search/indexing/local_import.rs @@ -553,17 +553,28 @@ async fn index_versions( let dependencies: Vec = sqlx::query!( " - SELECT mod_dependency_id as \"mod_dependency_id: DBProjectId\" - FROM dependencies + SELECT d.mod_dependency_id as \"mod_dependency_id: DBProjectId\", m.slug as \"slug\" FROM dependencies d + INNER JOIN mods m ON m.id = d.mod_dependency_id WHERE dependent_id = $1", version_id.0 ) - .fetch_all(pool) - .await? - .iter() - .flat_map(|r| r.mod_dependency_id) - .map(|id| crate::models::ids::ProjectId::from(id).to_string()) - .collect(); + .fetch_all(pool) + .await? + .iter() + .flat_map(|r| { + let mut v = Vec::new(); + + if let Some(id) = r.mod_dependency_id { + v.push(crate::models::ids::ProjectId::from(id).to_string()) + } + + if let Some(slug) = &r.slug { + v.push(slug.to_string()) + } + + v + }) + .collect(); res_versions .entry(*project_id) From e604d7e884498bfcd01834a836e4a24f5aabf9db Mon Sep 17 00:00:00 2001 From: IThundxr Date: Mon, 16 Feb 2026 22:02:27 -0500 Subject: [PATCH 3/3] Run sqlx prepare --- ...f4eeff66ab4165a9f4980032e114db4dc1286.json | 26 ----------------- ...e789420301ac35f23276229f39a8de8e8a558.json | 28 +++++++++++++++++++ ...d2402f52fea71e27b08e7926fcc2a9e62c0f3.json | 20 ------------- ...afedb074492b4ec7f2457c14113f5fd13aa02.json | 18 ------------ ...e5c93783c7641b019fdb698a1ec0be1393606.json | 17 ----------- 5 files changed, 28 insertions(+), 81 deletions(-) delete mode 100644 apps/labrinth/.sqlx/query-1adbd24d815107e13bc1440c7a8f4eeff66ab4165a9f4980032e114db4dc1286.json create mode 100644 apps/labrinth/.sqlx/query-678e51366948f5a41de74182e5de789420301ac35f23276229f39a8de8e8a558.json delete mode 100644 apps/labrinth/.sqlx/query-b92b5bb7d179c4fcdbc45600ccfd2402f52fea71e27b08e7926fcc2a9e62c0f3.json delete mode 100644 apps/labrinth/.sqlx/query-cd5ccd618fb3cc41646a6de86f9afedb074492b4ec7f2457c14113f5fd13aa02.json delete mode 100644 apps/labrinth/.sqlx/query-cec4240c7c848988b3dfd13e3f8e5c93783c7641b019fdb698a1ec0be1393606.json diff --git a/apps/labrinth/.sqlx/query-1adbd24d815107e13bc1440c7a8f4eeff66ab4165a9f4980032e114db4dc1286.json b/apps/labrinth/.sqlx/query-1adbd24d815107e13bc1440c7a8f4eeff66ab4165a9f4980032e114db4dc1286.json deleted file mode 100644 index 921f7f92d9..0000000000 --- a/apps/labrinth/.sqlx/query-1adbd24d815107e13bc1440c7a8f4eeff66ab4165a9f4980032e114db4dc1286.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n id,\n status AS \"status: PayoutStatus\"\n FROM payouts\n ORDER BY id\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "status: PayoutStatus", - "type_info": "Varchar" - } - ], - "parameters": { - "Left": [] - }, - "nullable": [ - false, - false - ] - }, - "hash": "1adbd24d815107e13bc1440c7a8f4eeff66ab4165a9f4980032e114db4dc1286" -} diff --git a/apps/labrinth/.sqlx/query-678e51366948f5a41de74182e5de789420301ac35f23276229f39a8de8e8a558.json b/apps/labrinth/.sqlx/query-678e51366948f5a41de74182e5de789420301ac35f23276229f39a8de8e8a558.json new file mode 100644 index 0000000000..bd0481fc9b --- /dev/null +++ b/apps/labrinth/.sqlx/query-678e51366948f5a41de74182e5de789420301ac35f23276229f39a8de8e8a558.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT d.mod_dependency_id as \"mod_dependency_id: DBProjectId\", m.slug as \"slug\" FROM dependencies d\n INNER JOIN mods m ON m.id = d.mod_dependency_id\n WHERE dependent_id = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "mod_dependency_id: DBProjectId", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "slug", + "type_info": "Varchar" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + true, + true + ] + }, + "hash": "678e51366948f5a41de74182e5de789420301ac35f23276229f39a8de8e8a558" +} diff --git a/apps/labrinth/.sqlx/query-b92b5bb7d179c4fcdbc45600ccfd2402f52fea71e27b08e7926fcc2a9e62c0f3.json b/apps/labrinth/.sqlx/query-b92b5bb7d179c4fcdbc45600ccfd2402f52fea71e27b08e7926fcc2a9e62c0f3.json deleted file mode 100644 index 89bd8147dc..0000000000 --- a/apps/labrinth/.sqlx/query-b92b5bb7d179c4fcdbc45600ccfd2402f52fea71e27b08e7926fcc2a9e62c0f3.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT status AS \"status: PayoutStatus\" FROM payouts WHERE id = 1", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "status: PayoutStatus", - "type_info": "Varchar" - } - ], - "parameters": { - "Left": [] - }, - "nullable": [ - false - ] - }, - "hash": "b92b5bb7d179c4fcdbc45600ccfd2402f52fea71e27b08e7926fcc2a9e62c0f3" -} diff --git a/apps/labrinth/.sqlx/query-cd5ccd618fb3cc41646a6de86f9afedb074492b4ec7f2457c14113f5fd13aa02.json b/apps/labrinth/.sqlx/query-cd5ccd618fb3cc41646a6de86f9afedb074492b4ec7f2457c14113f5fd13aa02.json deleted file mode 100644 index 469c30168a..0000000000 --- a/apps/labrinth/.sqlx/query-cd5ccd618fb3cc41646a6de86f9afedb074492b4ec7f2457c14113f5fd13aa02.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO payouts (id, method, platform_id, status, user_id, amount, created)\n VALUES ($1, $2, $3, $4, $5, 10.0, NOW())\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Text", - "Text", - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "cd5ccd618fb3cc41646a6de86f9afedb074492b4ec7f2457c14113f5fd13aa02" -} diff --git a/apps/labrinth/.sqlx/query-cec4240c7c848988b3dfd13e3f8e5c93783c7641b019fdb698a1ec0be1393606.json b/apps/labrinth/.sqlx/query-cec4240c7c848988b3dfd13e3f8e5c93783c7641b019fdb698a1ec0be1393606.json deleted file mode 100644 index 52e020ebf2..0000000000 --- a/apps/labrinth/.sqlx/query-cec4240c7c848988b3dfd13e3f8e5c93783c7641b019fdb698a1ec0be1393606.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO payouts (id, method, platform_id, status, user_id, amount, created)\n VALUES ($1, $2, NULL, $3, $4, 10.00, NOW())\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Text", - "Varchar", - "Int8" - ] - }, - "nullable": [] - }, - "hash": "cec4240c7c848988b3dfd13e3f8e5c93783c7641b019fdb698a1ec0be1393606" -}