Skip to content

Commit

Permalink
database: add pipeline
Browse files Browse the repository at this point in the history
I'm too lazy to read docs, if this doesn't work, might as well fallback to regular method of fetch -> update
  • Loading branch information
Itz-fork committed Jan 2, 2024
1 parent 567b887 commit d22eaa0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions megadl/helpers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit d22eaa0

Please sign in to comment.