Improve tap-to-view deletion query

This commit is contained in:
trevor-signal 2024-11-21 14:47:52 -05:00 committed by GitHub
parent 34cc87e8a8
commit 31373706d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 8 deletions

View file

@ -4584,7 +4584,8 @@ function getNextTapToViewMessageTimestampToAgeOut(
`
SELECT json FROM messages
WHERE
isViewOnce = 1
-- we want this query to use the messages_view_once index rather than received_at
likelihood(isViewOnce = 1, 0.01)
AND (isErased IS NULL OR isErased != 1)
ORDER BY received_at ASC, sent_at ASC
LIMIT 1;
@ -4595,9 +4596,8 @@ function getNextTapToViewMessageTimestampToAgeOut(
if (!row) {
return undefined;
}
const data = jsonToObject<MessageType>(row.json);
const result = data.received_at_ms || data.received_at;
const result = data.received_at_ms;
return isNormalNumber(result) ? result : undefined;
}
@ -4613,8 +4613,9 @@ function getTapToViewMessagesNeedingErase(
WHERE
isViewOnce = 1
AND (isErased IS NULL OR isErased != 1)
AND received_at <= $maxTimestamp
ORDER BY received_at ASC, sent_at ASC;
AND (
IFNULL(json ->> '$.received_at_ms', 0) <= $maxTimestamp
)
`
)
.all({