mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
feat(handleEvent7): update keys/reactions directly
TODO: convert reactions to jsonb TODO: convert to kysely rather than raw SQL
This commit is contained in:
parent
aae00cdc10
commit
bc24bb975c
1 changed files with 22 additions and 10 deletions
|
|
@ -112,17 +112,29 @@ async function handleEvent7(kysely: Kysely<DittoTables>, event: NostrEvent, x: n
|
||||||
|
|
||||||
if (id && emoji && (['+', '-'].includes(emoji) || /^\p{RGI_Emoji}$/v.test(emoji))) {
|
if (id && emoji && (['+', '-'].includes(emoji) || /^\p{RGI_Emoji}$/v.test(emoji))) {
|
||||||
const baka = await sql`
|
const baka = await sql`
|
||||||
UPDATE event_stats
|
UPDATE
|
||||||
SET reactions = jsonb_set(
|
event_stats
|
||||||
reactions::jsonb,
|
SET
|
||||||
|
reactions = CASE WHEN (
|
||||||
|
jsonb_set(
|
||||||
|
reactions :: jsonb,
|
||||||
ARRAY[${emoji}],
|
ARRAY[${emoji}],
|
||||||
CASE WHEN reactions::jsonb->${emoji} IS NULL THEN ${x}
|
CASE WHEN reactions :: jsonb -> ${emoji} IS NULL THEN ${x} ELSE to_jsonb(
|
||||||
ELSE to_jsonb((reactions::jsonb->${emoji})::int + ${x}::int)
|
(reactions :: jsonb -> ${emoji}):: int + ${x} :: int
|
||||||
END
|
) END
|
||||||
)
|
):: jsonb ->> ${emoji}
|
||||||
WHERE event_id = ${id}`
|
):: int = 0 THEN reactions :: jsonb - ${emoji} ELSE jsonb_set(
|
||||||
|
reactions :: jsonb,
|
||||||
|
ARRAY[${emoji}],
|
||||||
|
CASE WHEN reactions :: jsonb -> ${emoji} IS NULL THEN ${x} ELSE to_jsonb(
|
||||||
|
(reactions :: jsonb -> ${emoji}):: int + ${x} :: int
|
||||||
|
) END
|
||||||
|
) END,
|
||||||
|
reactions_count = reactions_count + ${x}
|
||||||
|
WHERE
|
||||||
|
event_id = ${id}
|
||||||
|
`
|
||||||
.execute(kysely);
|
.execute(kysely);
|
||||||
|
|
||||||
console.log(baka);
|
console.log(baka);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue