From d22eaa0ffb7474c490b13808d7ca4707a2491a4c Mon Sep 17 00:00:00 2001 From: Itz-fork Date: Tue, 2 Jan 2024 13:51:32 +0530 Subject: [PATCH] database: add pipeline I'm too lazy to read docs, if this doesn't work, might as well fallback to regular method of fetch -> update --- megadl/helpers/database.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/megadl/helpers/database.py b/megadl/helpers/database.py index 8c1787da..89f4a799 100644 --- a/megadl/helpers/database.py +++ b/megadl/helpers/database.py @@ -42,15 +42,22 @@ async def plus_fl_count( await self.mongoc.update_async( self.coll_users, {"_id": user_id}, - {"$inc": {"total_downloads": downloads}}, + [ + {"$match": {"_id": user_id}}, + {"$inc": {"total_downloads": downloads}}, + {"$replaceWith": {"$mergeObjects": ["$$ROOT", "$$CURRENT"]}}, + ], use_given=True, - upsert=False, ) elif uploads: await self.mongoc.update_async( self.coll_users, {"_id": user_id}, - {"$inc": {"total_uploads": uploads}}, + [ + {"$match": {"_id": user_id}}, + {"$inc": {"total_uploads": uploads}}, + {"$replaceWith": {"$mergeObjects": ["$$ROOT", "$$CURRENT"]}}, + ], use_given=True, upsert=False, )