Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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.

8 changes: 8 additions & 0 deletions apps/labrinth/src/search/backend/meilisearch/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ const DEFAULT_DISPLAYED_ATTRIBUTES: &[&str] = &[
"gallery",
"featured_gallery",
"color",
"required_dependencies",
"optional_dependencies",
"embedded_dependencies",
"incompatibilities",
// 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",
Expand Down Expand Up @@ -696,6 +700,10 @@ const DEFAULT_SORTABLE_ATTRIBUTES: &[&str] = &[
"date_created",
"date_modified",
"version_published_timestamp",
"required_dependencies",
"optional_dependencies",
"embedded_dependencies",
"incompatibilities",
"minecraft_java_server.verified_plays_2w",
"minecraft_java_server.ping.data.players_online",
];
45 changes: 45 additions & 0 deletions apps/labrinth/src/search/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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?;
Comment on lines +624 to +632
Copy link
Copy Markdown
Contributor

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.


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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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:

struct Dependency {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    version: Option<Id>,
    project: Id,
}

}

res_versions
.entry(*project_id)
.or_default()
Expand All @@ -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,
});
}
}
Expand Down
14 changes: 14 additions & 0 deletions apps/labrinth/src/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[serde(default, skip_serializing_if = "Vec::is_empty")]


// 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.
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[serde(default, skip_serializing_if = "Vec::is_empty")]


// 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.
Expand Down Expand Up @@ -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,
Expand Down
Loading