stop the peek table growing by reusing rows correctly

This commit is contained in:
Matthew Hodgson 2020-09-10 12:28:36 +01:00
parent b1d1ccdbc8
commit 9561843772
2 changed files with 6 additions and 4 deletions

View file

@ -44,7 +44,9 @@ CREATE INDEX IF NOT EXISTS syncapi_peeks_user_id_device_id_idx ON syncapi_peeks(
const insertPeekSQL = "" +
"INSERT INTO syncapi_peeks" +
" (room_id, user_id, device_id, creation_ts)" +
" VALUES ($1, $2, $3, $4) RETURNING id"
" VALUES ($1, $2, $3, $4)" +
" ON CONFLICT (room_id, user_id, device_id) DO UPDATE SET deleted=false, creation_ts=$4" +
" RETURNING id"
const deletePeekSQL = "" +
"UPDATE syncapi_peeks SET deleted=true, id=nextval('syncapi_stream_id') WHERE room_id = $1 AND user_id = $2 AND device_id = $3 RETURNING id"

View file

@ -42,9 +42,9 @@ CREATE INDEX IF NOT EXISTS syncapi_peeks_user_id_device_id_idx ON syncapi_peeks(
`
const insertPeekSQL = "" +
"INSERT INTO syncapi_peeks" +
" (id, room_id, user_id, device_id, creation_ts)" +
" VALUES ($1, $2, $3, $4, $5)"
"INSERT OR REPLACE INTO syncapi_peeks" +
" (id, room_id, user_id, device_id, creation_ts, deleted)" +
" VALUES ($1, $2, $3, $4, $5, false)"
const deletePeekSQL = "" +
"UPDATE syncapi_peeks SET deleted=true, id=$1 WHERE room_id = $2 AND user_id = $3 AND device_id = $4"