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::{
|
use crate::{
|
||||||
database::{
|
database::{
|
||||||
PgPool,
|
PgPool,
|
||||||
models::{DBProjectId, DBVersion, DBVersionId},
|
models::{DBProjectId, DBVersionId},
|
||||||
},
|
},
|
||||||
models::{
|
models::{
|
||||||
ids::{ProjectId, VersionId},
|
ids::{ProjectId, VersionId},
|
||||||
@@ -326,37 +326,28 @@ async fn fetch_dependent_version_projects(
|
|||||||
return Ok(HashMap::new());
|
return Ok(HashMap::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let dependent_on_version_ids =
|
let dependent_on_version_ids = dependent_on_version_ids
|
||||||
dependent_on_version_ids.into_iter().collect::<Vec<_>>();
|
.into_iter()
|
||||||
let versions =
|
.map(|version_id| version_id.0)
|
||||||
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)
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let server_projects = sqlx::query!(
|
let versions = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT id FROM mods
|
SELECT v.id, v.mod_id
|
||||||
WHERE id = ANY($1)
|
FROM versions v
|
||||||
AND components ? 'minecraft_server'
|
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)
|
.fetch_all(cx.pool)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to fetch server dependent projects")?
|
.wrap_internal_err("failed to fetch dependent version projects")?;
|
||||||
.into_iter()
|
|
||||||
.map(|project| DBProjectId(project.id))
|
|
||||||
.collect::<HashSet<_>>();
|
|
||||||
|
|
||||||
Ok(versions
|
Ok(versions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|version| {
|
.map(|version| (DBVersionId(version.id), DBProjectId(version.mod_id)))
|
||||||
(!server_projects.contains(&version.inner.project_id))
|
|
||||||
.then_some((version.inner.id, version.inner.project_id))
|
|
||||||
})
|
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -330,7 +330,6 @@ pub async fn fetch_analytics(
|
|||||||
let mut query_clickhouse_cx = QueryClickhouseContext {
|
let mut query_clickhouse_cx = QueryClickhouseContext {
|
||||||
clickhouse: &clickhouse,
|
clickhouse: &clickhouse,
|
||||||
pool: &pool,
|
pool: &pool,
|
||||||
redis: &redis,
|
|
||||||
req: &req,
|
req: &req,
|
||||||
time_slices: &mut time_slices,
|
time_slices: &mut time_slices,
|
||||||
project_ids: &project_ids,
|
project_ids: &project_ids,
|
||||||
@@ -677,7 +676,6 @@ async fn fetch_project_status_change_events(
|
|||||||
pub(crate) struct QueryClickhouseContext<'a> {
|
pub(crate) struct QueryClickhouseContext<'a> {
|
||||||
pub(crate) clickhouse: &'a clickhouse::Client,
|
pub(crate) clickhouse: &'a clickhouse::Client,
|
||||||
pub(crate) pool: &'a PgPool,
|
pub(crate) pool: &'a PgPool,
|
||||||
pub(crate) redis: &'a RedisPool,
|
|
||||||
pub(crate) req: &'a GetRequest,
|
pub(crate) req: &'a GetRequest,
|
||||||
pub(crate) time_slices: &'a mut [TimeSlice],
|
pub(crate) time_slices: &'a mut [TimeSlice],
|
||||||
pub(crate) project_ids: &'a [DBProjectId],
|
pub(crate) project_ids: &'a [DBProjectId],
|
||||||
|
|||||||
@@ -415,6 +415,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- '127.0.0.1:8123:8123'
|
- '127.0.0.1:8123:8123'
|
||||||
environment:
|
environment:
|
||||||
|
CLICKHOUSE_DB: staging_ariadne
|
||||||
CLICKHOUSE_USER: default
|
CLICKHOUSE_USER: default
|
||||||
CLICKHOUSE_PASSWORD: default
|
CLICKHOUSE_PASSWORD: default
|
||||||
healthcheck:
|
healthcheck:
|
||||||
|
|||||||
Reference in New Issue
Block a user