This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree 2 files changed +12
-4
lines changed
synapse/storage/databases/main
2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change
1
+ As an optimisation, use `TRUNCATE` on Postgres when clearing the user directory tables.
Original file line number Diff line number Diff line change @@ -698,10 +698,17 @@ async def delete_all_from_user_dir(self) -> None:
698
698
"""Delete the entire user directory"""
699
699
700
700
def _delete_all_from_user_dir_txn (txn : LoggingTransaction ) -> None :
701
- txn .execute ("DELETE FROM user_directory" )
702
- txn .execute ("DELETE FROM user_directory_search" )
703
- txn .execute ("DELETE FROM users_in_public_rooms" )
704
- txn .execute ("DELETE FROM users_who_share_private_rooms" )
701
+ # SQLite doesn't support TRUNCATE.
702
+ # On Postgres, DELETE FROM does a table scan but TRUNCATE is more efficient.
703
+ truncate = (
704
+ "DELETE FROM"
705
+ if isinstance (self .database_engine , Sqlite3Engine )
706
+ else "TRUNCATE"
707
+ )
708
+ txn .execute (f"{ truncate } user_directory" )
709
+ txn .execute (f"{ truncate } user_directory_search" )
710
+ txn .execute (f"{ truncate } users_in_public_rooms" )
711
+ txn .execute (f"{ truncate } users_who_share_private_rooms" )
705
712
txn .call_after (self .get_user_in_directory .invalidate_all )
706
713
707
714
await self .db_pool .runInteraction (
You can’t perform that action at this time.
0 commit comments