From 2cdc454f3e464adbe05da2ba0dd34685d0a5ad00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 7 May 2023 23:48:09 -0400 Subject: [PATCH] use order by --- src/database/postgres.js | 2 +- src/database/postgres/sorted.js | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/database/postgres.js b/src/database/postgres.js index 86f7d3e418..f09041c7c3 100644 --- a/src/database/postgres.js +++ b/src/database/postgres.js @@ -290,7 +290,7 @@ PARALLEL SAFE`); if (!res.rows[0].d) { await client.query(` CREATE FUNCTION "nodebb_get_sorted_set_members_withscores"(TEXT) RETURNS JSON AS $$ - SELECT json_agg(json_build_object('value', z."value", 'score', z."score")) as item + SELECT json_agg(json_build_object('value', z."value", 'score', z."score") ORDER BY z."score" ASC) as item FROM "legacy_object_live" o INNER JOIN "legacy_zset" z ON o."_key" = z."_key" diff --git a/src/database/postgres/sorted.js b/src/database/postgres/sorted.js index 254353178b..2ed679b683 100644 --- a/src/database/postgres/sorted.js +++ b/src/database/postgres/sorted.js @@ -492,12 +492,6 @@ SELECT "_key" k, FROM UNNEST($1::TEXT[]) "_key";`, values: [keys], }); - // TODO: move this sort into nodebb_get_sorted_set_members_withscores? - res.rows.forEach((r) => { - if (r && r.m) { - r.m.sort((a, b) => a.score - b.score); - } - }); return keys.map(k => (res.rows.find(r => r.k === k) || {}).m || []); };