From e2fc0acdfec6d8f2f569ad1580b7b3525fdd5b89 Mon Sep 17 00:00:00 2001 From: Christoph Johannes Kleine Date: Sun, 30 May 2021 20:24:09 +0200 Subject: [PATCH] fix #3599 --- synapse/storage/databases/main/devices.py | 15 +++++++++++++ ...move_deleted_devices_from_device_inbox.sql | 21 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 synapse/storage/schema/main/delta/60/99remove_deleted_devices_from_device_inbox.sql diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py index 18f07d96dcd0..d09112d91756 100644 --- a/synapse/storage/databases/main/devices.py +++ b/synapse/storage/databases/main/devices.py @@ -1130,6 +1130,12 @@ async def delete_device(self, user_id: str, device_id: str) -> None: desc="delete_device", ) + await self.db_pool.simple_delete_one( + table="device_inbox", + keyvalues={"user_id": user_id, "device_id": device_id}, + desc="delete_device", + ) + self.device_id_exists_cache.invalidate((user_id, device_id)) async def delete_devices(self, user_id: str, device_ids: List[str]) -> None: @@ -1146,6 +1152,15 @@ async def delete_devices(self, user_id: str, device_ids: List[str]) -> None: keyvalues={"user_id": user_id, "hidden": False}, desc="delete_devices", ) + + await self.db_pool.simple_delete_many( + table="device_inbox", + column="device_id", + iterable=device_ids, + keyvalues={"user_id": user_id}, + desc="delete_devices", + ) + for device_id in device_ids: self.device_id_exists_cache.invalidate((user_id, device_id)) diff --git a/synapse/storage/schema/main/delta/60/99remove_deleted_devices_from_device_inbox.sql b/synapse/storage/schema/main/delta/60/99remove_deleted_devices_from_device_inbox.sql new file mode 100644 index 000000000000..4b069bf0a629 --- /dev/null +++ b/synapse/storage/schema/main/delta/60/99remove_deleted_devices_from_device_inbox.sql @@ -0,0 +1,21 @@ +/* Copyright 2021 The Matrix.org Foundation C.I.C + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +--- Remove messages from the device_inbox table which where sent to an +--- allready deleted device. +--- This schould run as the last task, it may take a little bit longer +--- to finish. + +DELETE FROM device_inbox WHERE device_id NOT IN (SELECT device_id FROM devices);