fix(userbot): mark deletions per row to stay under timescale decompression limit
This commit is contained in:
@@ -30,6 +30,16 @@ ON CONFLICT (account_id, chat_id, message_id, date) DO UPDATE SET
|
||||
edited_at = now()
|
||||
"""
|
||||
|
||||
_FIND_DELETED = """
|
||||
SELECT chat_id, message_id, date FROM messages
|
||||
WHERE account_id = $1 AND message_id = ANY($2::bigint[]) AND deleted_at IS NULL
|
||||
"""
|
||||
|
||||
_MARK_DELETED = """
|
||||
UPDATE messages SET deleted_at = now()
|
||||
WHERE account_id = $1 AND chat_id = $2 AND message_id = $3 AND date = $4
|
||||
"""
|
||||
|
||||
_INSERT_VERSION = """
|
||||
INSERT INTO message_versions
|
||||
(account_id, chat_id, message_id, observed_at, edit_date, text, raw)
|
||||
@@ -128,30 +138,34 @@ async def max_message_id(
|
||||
)
|
||||
|
||||
|
||||
async def _mark_deleted(
|
||||
pool: asyncpg.Pool, account_id: int, rows: list[asyncpg.Record]
|
||||
) -> None:
|
||||
for row in rows:
|
||||
await pool.execute(
|
||||
_MARK_DELETED, account_id, row["chat_id"], row["message_id"], row["date"]
|
||||
)
|
||||
|
||||
|
||||
async def mark_deleted_box(
|
||||
pool: asyncpg.Pool, account_id: int, message_ids: list[int]
|
||||
) -> None:
|
||||
await pool.execute(
|
||||
"UPDATE messages SET deleted_at = now() "
|
||||
"WHERE account_id = $1 AND message_id = ANY($2::bigint[]) "
|
||||
"AND chat_id > $3 AND deleted_at IS NULL",
|
||||
rows = await pool.fetch(
|
||||
f"{_FIND_DELETED} AND chat_id > $3",
|
||||
account_id,
|
||||
message_ids,
|
||||
CHANNEL_ID_THRESHOLD,
|
||||
)
|
||||
await _mark_deleted(pool, account_id, rows)
|
||||
|
||||
|
||||
async def mark_deleted_channel(
|
||||
pool: asyncpg.Pool, account_id: int, chat_id: int, message_ids: list[int]
|
||||
) -> None:
|
||||
await pool.execute(
|
||||
"UPDATE messages SET deleted_at = now() "
|
||||
"WHERE account_id = $1 AND chat_id = $2 AND message_id = ANY($3::bigint[]) "
|
||||
"AND deleted_at IS NULL",
|
||||
account_id,
|
||||
chat_id,
|
||||
message_ids,
|
||||
rows = await pool.fetch(
|
||||
f"{_FIND_DELETED} AND chat_id = $3", account_id, message_ids, chat_id
|
||||
)
|
||||
await _mark_deleted(pool, account_id, rows)
|
||||
|
||||
|
||||
async def add_version( # noqa: PLR0913
|
||||
|
||||
Reference in New Issue
Block a user