fix abysmal postgresql performance in getSortedSetsMembers (#8030)

* refactor postgres upgrade function to use async

* add function wrapper for getting the elements of a sorted set to avoid postgres planning the query with a nested sequential scan

* fix fatal(?!) lint errors

* add missing await

* bump PostgreSQL version on Travis CI to one that isn't over 3 years out of date
This commit is contained in:
Ben Lubar
2019-11-13 13:45:48 -06:00
committed by Barış Soner Uşaklı
parent b47f1769e4
commit f65922297d
3 changed files with 76 additions and 67 deletions

View File

@@ -463,19 +463,14 @@ SELECT o."_key" k
const res = await module.pool.query({
name: 'getSortedSetsMembers',
text: `
SELECT o."_key" k,
array_agg(z."value" ORDER BY z."score" ASC) m
FROM "legacy_object_live" o
INNER JOIN "legacy_zset" z
ON o."_key" = z."_key"
AND o."type" = z."type"
WHERE o."_key" = ANY($1::TEXT[])
GROUP BY o."_key"`,
SELECT "_key" k,
"nodebb_get_sorted_set_members"("_key") m
FROM UNNEST($1::TEXT[]) "_key";`,
values: [keys],
});
return keys.map(function (k) {
return (res.rows.find(r => r.k === k) || { m: [] }).m;
return (res.rows.find(r => r.k === k) || {}).m || [];
});
};