mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 00:55:25 +00:00
fix: improve analytics dependents query (#7025)
* fix: improve analytics dependents query * fix up compose
This commit is contained in:
Generated
-22
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT id FROM mods\n WHERE id = ANY($1)\n AND components ? 'minecraft_server'\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8Array"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "6ebb0cffc875f50ebe95b91e4735f1c520155d65a5c51021224ab4461c688db8"
|
||||
}
|
||||
Generated
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT v.id, v.mod_id\n FROM versions v\n INNER JOIN mods m ON m.id = v.mod_id\n WHERE\n v.id = ANY($1)\n AND jsonb_typeof(m.components -> 'minecraft_server') IS DISTINCT FROM 'object'\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "mod_id",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8Array"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "93b19a49ae305ab760792d22c5b955a75323663880b47aa9ed42c9f33cd65f16"
|
||||
}
|
||||
@@ -14,7 +14,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Error as _};
|
||||
use crate::{
|
||||
database::{
|
||||
PgPool,
|
||||
models::{DBProjectId, DBVersion, DBVersionId},
|
||||
models::{DBProjectId, DBVersionId},
|
||||
},
|
||||
models::{
|
||||
ids::{ProjectId, VersionId},
|
||||
@@ -326,37 +326,28 @@ async fn fetch_dependent_version_projects(
|
||||
return Ok(HashMap::new());
|
||||
}
|
||||
|
||||
let dependent_on_version_ids =
|
||||
dependent_on_version_ids.into_iter().collect::<Vec<_>>();
|
||||
let versions =
|
||||
DBVersion::get_many(&dependent_on_version_ids, cx.pool, cx.redis)
|
||||
.await?;
|
||||
|
||||
let dependent_project_ids = versions
|
||||
.iter()
|
||||
.map(|version| version.inner.project_id.0)
|
||||
let dependent_on_version_ids = dependent_on_version_ids
|
||||
.into_iter()
|
||||
.map(|version_id| version_id.0)
|
||||
.collect::<Vec<_>>();
|
||||
let server_projects = sqlx::query!(
|
||||
let versions = sqlx::query!(
|
||||
"
|
||||
SELECT id FROM mods
|
||||
WHERE id = ANY($1)
|
||||
AND components ? 'minecraft_server'
|
||||
SELECT v.id, v.mod_id
|
||||
FROM versions v
|
||||
INNER JOIN mods m ON m.id = v.mod_id
|
||||
WHERE
|
||||
v.id = ANY($1)
|
||||
AND jsonb_typeof(m.components -> 'minecraft_server') IS DISTINCT FROM 'object'
|
||||
",
|
||||
&dependent_project_ids,
|
||||
&dependent_on_version_ids,
|
||||
)
|
||||
.fetch_all(cx.pool)
|
||||
.await
|
||||
.wrap_internal_err("failed to fetch server dependent projects")?
|
||||
.into_iter()
|
||||
.map(|project| DBProjectId(project.id))
|
||||
.collect::<HashSet<_>>();
|
||||
.wrap_internal_err("failed to fetch dependent version projects")?;
|
||||
|
||||
Ok(versions
|
||||
.into_iter()
|
||||
.filter_map(|version| {
|
||||
(!server_projects.contains(&version.inner.project_id))
|
||||
.then_some((version.inner.id, version.inner.project_id))
|
||||
})
|
||||
.map(|version| (DBVersionId(version.id), DBProjectId(version.mod_id)))
|
||||
.collect())
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +330,6 @@ pub async fn fetch_analytics(
|
||||
let mut query_clickhouse_cx = QueryClickhouseContext {
|
||||
clickhouse: &clickhouse,
|
||||
pool: &pool,
|
||||
redis: &redis,
|
||||
req: &req,
|
||||
time_slices: &mut time_slices,
|
||||
project_ids: &project_ids,
|
||||
@@ -677,7 +676,6 @@ async fn fetch_project_status_change_events(
|
||||
pub(crate) struct QueryClickhouseContext<'a> {
|
||||
pub(crate) clickhouse: &'a clickhouse::Client,
|
||||
pub(crate) pool: &'a PgPool,
|
||||
pub(crate) redis: &'a RedisPool,
|
||||
pub(crate) req: &'a GetRequest,
|
||||
pub(crate) time_slices: &'a mut [TimeSlice],
|
||||
pub(crate) project_ids: &'a [DBProjectId],
|
||||
|
||||
@@ -415,6 +415,7 @@ services:
|
||||
ports:
|
||||
- '127.0.0.1:8123:8123'
|
||||
environment:
|
||||
CLICKHOUSE_DB: staging_ariadne
|
||||
CLICKHOUSE_USER: default
|
||||
CLICKHOUSE_PASSWORD: default
|
||||
healthcheck:
|
||||
|
||||
Reference in New Issue
Block a user