diff --git a/megadl/helpers/database.py b/megadl/helpers/database.py index 969e23ff..cb75aa0e 100644 --- a/megadl/helpers/database.py +++ b/megadl/helpers/database.py @@ -29,9 +29,11 @@ async def add(self, user_id: int): no_modify=True, upsert=True, ) - return (await self.mongoc.find_async( - self.coll_users, {"_id": user_id}, {"_id": 0, "status": 1} - ))["status"] + return ( + await self.mongoc.find_async( + self.coll_users, {"_id": user_id}, {"_id": 0, "status": 1} + ) + )["status"] async def plus_fl_count( self, user_id: int, downloads: int | None = None, uploads: int | None = None @@ -41,12 +43,14 @@ async def plus_fl_count( self.coll_users, {"_id": user_id}, {"$inc": {"total_downloads": downloads}}, + use_given=True, ) elif uploads: await self.mongoc.update_async( self.coll_users, {"_id": user_id}, {"$inc": {"total_uploads": uploads}}, + use_given=True, ) async def delete(self, user_id: int): diff --git a/megadl/lib/aiomongo.py b/megadl/lib/aiomongo.py index 810986c2..a3a6eb7f 100644 --- a/megadl/lib/aiomongo.py +++ b/megadl/lib/aiomongo.py @@ -53,6 +53,7 @@ async def update_async( query: dict, value: dict, no_modify: bool = False, + use_given: bool = False, *args, **kwargs ): @@ -63,6 +64,8 @@ async def update_async( return await run_partial( coll.update_one, query, {"$setOnInsert": value}, *args, **kwargs ) + elif use_given: + return await run_partial(coll.update_one, query, value, *args, **kwargs) else: return await run_partial( coll.update_one, query, {"$set": value}, *args, **kwargs