From e2fc0acdfec6d8f2f569ad1580b7b3525fdd5b89 Mon Sep 17 00:00:00 2001 From: Christoph Johannes Kleine Date: Sun, 30 May 2021 20:24:09 +0200 Subject: [PATCH 1/5] 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); From 12d20b8bc7cbf4f2052ed26b003700e37ce9bf32 Mon Sep 17 00:00:00 2001 From: Christoph Johannes Kleine Date: Sun, 30 May 2021 20:37:05 +0200 Subject: [PATCH 2/5] add changelog --- changelog.d/10098.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/10098.bugfix diff --git a/changelog.d/10098.bugfix b/changelog.d/10098.bugfix new file mode 100644 index 000000000000..11ab4436e1e8 --- /dev/null +++ b/changelog.d/10098.bugfix @@ -0,0 +1 @@ +Fix a bug where messages in `device_inbox` table where not deleted, when deleting device(s). From 40ee6525d5536856f7c12446ba022400ba8d7cce Mon Sep 17 00:00:00 2001 From: Christoph Johannes Kleine Date: Tue, 1 Jun 2021 17:10:11 +0200 Subject: [PATCH 3/5] move sql file --- .../14remove_deleted_devices_from_device_inbox.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename synapse/storage/schema/main/delta/{60/99remove_deleted_devices_from_device_inbox.sql => 59/14remove_deleted_devices_from_device_inbox.sql} (100%) diff --git a/synapse/storage/schema/main/delta/60/99remove_deleted_devices_from_device_inbox.sql b/synapse/storage/schema/main/delta/59/14remove_deleted_devices_from_device_inbox.sql similarity index 100% rename from synapse/storage/schema/main/delta/60/99remove_deleted_devices_from_device_inbox.sql rename to synapse/storage/schema/main/delta/59/14remove_deleted_devices_from_device_inbox.sql From c49a2d35bad8b388931326abb6d3046dc255d381 Mon Sep 17 00:00:00 2001 From: Christoph Johannes Kleine Date: Sat, 16 Oct 2021 16:46:18 +0200 Subject: [PATCH 4/5] copy change from erikjohnston --- synapse/storage/databases/main/devices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py index d09112d91756..ded53d1a80e4 100644 --- a/synapse/storage/databases/main/devices.py +++ b/synapse/storage/databases/main/devices.py @@ -1130,7 +1130,7 @@ async def delete_device(self, user_id: str, device_id: str) -> None: desc="delete_device", ) - await self.db_pool.simple_delete_one( + await self.db_pool.simple_delete_many( table="device_inbox", keyvalues={"user_id": user_id, "device_id": device_id}, desc="delete_device", From 389c3f87b4102e28f4e62d682bc4b89d8c5c5225 Mon Sep 17 00:00:00 2001 From: Christoph Johannes Kleine Date: Sat, 16 Oct 2021 16:48:51 +0200 Subject: [PATCH 5/5] remove database schema change file (outdated) --- ...move_deleted_devices_from_device_inbox.sql | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 synapse/storage/schema/main/delta/59/14remove_deleted_devices_from_device_inbox.sql diff --git a/synapse/storage/schema/main/delta/59/14remove_deleted_devices_from_device_inbox.sql b/synapse/storage/schema/main/delta/59/14remove_deleted_devices_from_device_inbox.sql deleted file mode 100644 index 4b069bf0a629..000000000000 --- a/synapse/storage/schema/main/delta/59/14remove_deleted_devices_from_device_inbox.sql +++ /dev/null @@ -1,21 +0,0 @@ -/* 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);