Skip to content

Commit 6a3e081

Browse files
committed
fix(mods): index query optimizations
1 parent 736a3f2 commit 6a3e081

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/types/models/mod_entity.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,13 @@ impl Mod {
286286
"#;
287287

288288
let records: Vec<ModRecord> = sqlx::query_as(&format!(
289-
"SELECT
290-
q.id, q.repository, q.about,
291-
q.changelog, q.download_count,
292-
q.featured, q.created_at, q.updated_at, q.status
293-
FROM (
294-
SELECT
295-
m.id, m.repository, m.about, m.changelog,
296-
m.download_count, m.featured, m.created_at, m.updated_at, mvs.status,
297-
ROW_NUMBER() OVER (PARTITION BY m.id ORDER BY mv.id DESC) rn
298-
FROM mods m
299-
{}
300-
ORDER BY {}
301-
) q
302-
WHERE q.rn = 1
289+
"SELECT
290+
m.id, m.repository, m.about, m.changelog,
291+
m.download_count, m.featured, m.created_at, m.updated_at
292+
FROM mods m
293+
{}
294+
GROUP BY m.id
295+
ORDER BY {}
303296
LIMIT $11
304297
OFFSET $12",
305298
joins_filters, order
@@ -324,8 +317,8 @@ impl Mod {
324317

325318
let count: i64 = sqlx::query_scalar(&format!(
326319
"SELECT COUNT(DISTINCT m.id)
327-
FROM mods m
328-
{}",
320+
FROM mods m
321+
{}",
329322
joins_filters
330323
))
331324
.bind(&tags)

0 commit comments

Comments
 (0)