Skip to content

Commit

Permalink
database: fix value increment error
Browse files Browse the repository at this point in the history
  • Loading branch information
Itz-fork committed Jan 2, 2024
1 parent c45bdf0 commit 2745359
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions megadl/helpers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions megadl/lib/aiomongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async def update_async(
query: dict,
value: dict,
no_modify: bool = False,
use_given: bool = False,
*args,
**kwargs
):
Expand All @@ -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
Expand Down

0 comments on commit 2745359

Please sign in to comment.