-
Notifications
You must be signed in to change notification settings - Fork 424
feat(labrinth): Add support for dependencies in search #5385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
62e1268
c11117d
c14016b
e604d7e
4d42a2e
9c75143
2400c10
dde543f
cb7ae0d
c354f91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -461,6 +461,10 @@ pub async fn index_local( | |
| featured_gallery: featured_gallery.clone(), | ||
| open_source, | ||
| color: project.color.map(|x| x as u32), | ||
| required_dependencies: version.required_dependencies, | ||
| optional_dependencies: version.optional_dependencies, | ||
| embedded_dependencies: version.embedded_dependencies, | ||
| incompatibilities: version.incompatibilities, | ||
| loader_fields, | ||
| project_loader_fields: project_loader_fields.clone(), | ||
| // 'loaders' is aggregate of all versions' loaders | ||
|
|
@@ -482,6 +486,10 @@ struct PartialVersion { | |
| project_types: Vec<String>, | ||
| version_fields: Vec<QueryVersionField>, | ||
| date_published: DateTime<Utc>, | ||
| required_dependencies: Vec<String>, | ||
| optional_dependencies: Vec<String>, | ||
| embedded_dependencies: Vec<String>, | ||
| incompatibilities: Vec<String>, | ||
| } | ||
|
|
||
| async fn index_versions( | ||
|
|
@@ -608,6 +616,39 @@ async fn index_versions( | |
| .map(|(_, version_fields)| version_fields) | ||
| .unwrap_or_default(); | ||
|
|
||
| let mut required_dependencies: Vec<String> = Vec::new(); | ||
| let mut optional_dependencies: Vec<String> = Vec::new(); | ||
| let mut embedded_dependencies: Vec<String> = Vec::new(); | ||
| let mut incompatibilities: Vec<String> = Vec::new(); | ||
|
|
||
| let records = sqlx::query!( | ||
| " | ||
| SELECT d.mod_dependency_id as \"mod_dependency_id: DBProjectId\", d.dependency_type, 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?; | ||
|
|
||
| for r in records { | ||
| let v = match r.dependency_type.as_str() { | ||
| "required" => &mut required_dependencies, | ||
| "optional" => &mut optional_dependencies, | ||
| "embedded" => &mut embedded_dependencies, | ||
| "incompatible" => &mut incompatibilities, | ||
| _ => continue, | ||
| }; | ||
|
|
||
| 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()) | ||
| } | ||
|
Comment on lines
+643
to
+649
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love including both the slug and project ID, would include only the ID. The item type should be something like below instead of an either-id-or-slug string: |
||
| } | ||
|
|
||
| res_versions | ||
| .entry(*project_id) | ||
| .or_default() | ||
|
|
@@ -617,6 +658,10 @@ async fn index_versions( | |
| project_types: version_loader_data.project_types, | ||
| version_fields, | ||
| date_published: *date_published, | ||
| required_dependencies, | ||
| optional_dependencies, | ||
| embedded_dependencies, | ||
| incompatibilities, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,6 +254,11 @@ pub struct UploadSearchProject { | |
| pub open_source: bool, | ||
| pub color: Option<u32>, | ||
|
|
||
| pub required_dependencies: Vec<String>, | ||
| pub optional_dependencies: Vec<String>, | ||
| pub embedded_dependencies: Vec<String>, | ||
| pub incompatibilities: Vec<String>, | ||
|
Comment on lines
+257
to
+260
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // Hidden fields to get the Project model out of the search results. | ||
| pub loaders: Vec<String>, // Search uses loaders as categories- this is purely for the Project model. | ||
| pub project_loader_fields: HashMap<String, Vec<serde_json::Value>>, // Aggregation of loader_fields from all versions of the project, allowing for reconstruction of the Project model. | ||
|
|
@@ -295,6 +300,11 @@ pub struct ResultSearchProject { | |
| pub featured_gallery: Option<String>, | ||
| pub color: Option<u32>, | ||
|
|
||
| pub required_dependencies: Vec<String>, | ||
| pub optional_dependencies: Vec<String>, | ||
| pub embedded_dependencies: Vec<String>, | ||
| pub incompatibilities: Vec<String>, | ||
|
Comment on lines
+303
to
+306
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // Hidden fields to get the Project model out of the search results. | ||
| pub loaders: Vec<String>, // Search uses loaders as categories- this is purely for the Project model. | ||
| pub project_loader_fields: HashMap<String, Vec<serde_json::Value>>, // Aggregation of loader_fields from all versions of the project, allowing for reconstruction of the Project model. | ||
|
|
@@ -328,6 +338,10 @@ impl From<UploadSearchProject> for ResultSearchProject { | |
| gallery: source.gallery, | ||
| featured_gallery: source.featured_gallery, | ||
| color: source.color, | ||
| required_dependencies: source.required_dependencies, | ||
| optional_dependencies: source.optional_dependencies, | ||
| embedded_dependencies: source.embedded_dependencies, | ||
| incompatibilities: source.incompatibilities, | ||
| loaders: source.loaders, | ||
| project_loader_fields: source.project_loader_fields, | ||
| components: source.components, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query should be batched like the queries above it instead of running for every single version.
This doesn't account for version dependencies.
Would exclude embedded dependencies, at least for now, since it could drastically increase document size for modpacks which might have performance implications.