Chunking searches (#787)

* new attempt

* revised searching CTEs

* prepare fix

* fix tests

* fixes

* restructured project_item to use queries

* search changes! fmt clippy prepare

* small changes
This commit is contained in:
Wyatt Verchere
2023-12-08 22:14:17 -08:00
committed by GitHub
parent 945e5a2dc3
commit 235f4f10ef
28 changed files with 1784 additions and 1026 deletions

View File

@@ -16,6 +16,7 @@ use crate::models::projects::{
use crate::models::threads::ThreadId;
use crate::routes::v2_reroute;
use chrono::{DateTime, Utc};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use validator::Validate;
@@ -123,14 +124,25 @@ impl LegacyProject {
// - if loader is mrpack, this is a modpack
// the loaders are whatever the corresponding loader fields are
if versions_item.loaders == vec!["mrpack".to_string()] {
if loaders.contains(&"mrpack".to_string()) {
project_type = "modpack".to_string();
if let Some(mrpack_loaders) = versions_item
.version_fields
.iter()
.find(|f| f.field_name == "mrpack_loaders")
{
loaders = mrpack_loaders.value.as_strings();
if let Some(mrpack_loaders) = data.fields.iter().find(|f| f.0 == "mrpack_loaders") {
let values = mrpack_loaders
.1
.iter()
.filter_map(|v| v.as_str())
.map(|v| v.to_string())
.collect::<Vec<_>>();
// drop mrpack from loaders
loaders = loaders
.into_iter()
.filter(|l| l != "mrpack")
.collect::<Vec<_>>();
// and replace with mrpack_loaders
loaders.extend(values);
// remove duplicate loaders
loaders = loaders.into_iter().unique().collect::<Vec<_>>();
}
}
}
@@ -198,7 +210,7 @@ impl LegacyProject {
redis: &RedisPool,
) -> Result<Vec<Self>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
{
let version_ids: Vec<_> = data
.iter()
@@ -300,7 +312,7 @@ impl From<Version> for LegacyVersion {
// - if loader is mrpack, this is a modpack
// the v2 loaders are whatever the corresponding loader fields are
let mut loaders = data.loaders.into_iter().map(|l| l.0).collect::<Vec<_>>();
if loaders == vec!["mrpack".to_string()] {
if loaders.contains(&"mrpack".to_string()) {
if let Some((_, mrpack_loaders)) = data
.fields
.into_iter()