Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesKleine committed May 30, 2021
1 parent ed53bf3 commit e2fc0ac
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions synapse/storage/databases/main/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))

Expand Down
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit e2fc0ac

Please sign in to comment.