mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
feat: add getSortedSetMembersWithScores (#11579)
* feat: add getSortedSetMembersWithScores * lint: fix * test: fix redis * fix: mongo/psql
This commit is contained in:
committed by
GitHub
parent
163c977d2f
commit
f083cd559d
@@ -78,9 +78,13 @@ SELECT EXISTS(SELECT *
|
||||
EXISTS(SELECT *
|
||||
FROM "information_schema"."routines"
|
||||
WHERE "routine_schema" = 'public'
|
||||
AND "routine_name" = 'nodebb_get_sorted_set_members') c`);
|
||||
AND "routine_name" = 'nodebb_get_sorted_set_members') c,
|
||||
EXISTS(SELECT *
|
||||
FROM "information_schema"."routines"
|
||||
WHERE "routine_schema" = 'public'
|
||||
AND "routine_name" = 'nodebb_get_sorted_set_members_withscores') d`);
|
||||
|
||||
if (res.rows[0].a && res.rows[0].b && res.rows[0].c) {
|
||||
if (res.rows[0].a && res.rows[0].b && res.rows[0].c && res.rows[0].d) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -282,6 +286,21 @@ STABLE
|
||||
STRICT
|
||||
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
|
||||
FROM "legacy_object_live" o
|
||||
INNER JOIN "legacy_zset" z
|
||||
ON o."_key" = z."_key"
|
||||
AND o."type" = z."type"
|
||||
WHERE o."_key" = $1
|
||||
$$ LANGUAGE sql
|
||||
STABLE
|
||||
STRICT
|
||||
PARALLEL SAFE`);
|
||||
}
|
||||
} catch (ex) {
|
||||
await client.query(`ROLLBACK`);
|
||||
throw ex;
|
||||
|
||||
Reference in New Issue
Block a user