Skip to content

Commit

Permalink
Pyrofork: Clean usernames database before updating usernames database
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Oct 27, 2023
1 parent 1dc0c5c commit a78a723
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pyrogram/storage/mongo_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Tuple, Any

from .dummy_client import DummyMongoClient
from pymongo import MongoClient, UpdateOne
from pymongo import MongoClient, UpdateOne, DeleteMany
from pyrogram.storage.storage import Storage
from pyrogram.storage.sqlite_storage import get_input_peer

Expand Down Expand Up @@ -124,6 +124,11 @@ async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]):

async def update_usernames(self, usernames: List[Tuple[int, str]]):
s = int(time.time())
bulk_delete = [
DeleteMany(
{'peer_id': i[0]}
) for i in usernames
]
bulk = [
UpdateOne(
{'_id': i[1]},
Expand All @@ -136,6 +141,9 @@ async def update_usernames(self, usernames: List[Tuple[int, str]]):
]
if not bulk:
return
await self._usernames.bulk_write(
bulk_delete
)
await self._usernames.bulk_write(
bulk
)
Expand Down

0 comments on commit a78a723

Please sign in to comment.