diff options
| author | 2020-09-22 21:55:09 +0530 | |
|---|---|---|
| committer | 2020-09-22 21:55:09 +0530 | |
| commit | ec0db2dd98e55f8bf5ba1c07375e196933129f99 (patch) | |
| tree | 5f786a4d6ccc96dab4f82fd309a4a8e4f6d74340 | |
| parent | Merge remote-tracking branch 'upstream/master' into smart_syncing_users (diff) | |
Refactor code to make use of bulk create and update API endpoints.
instead of creating and updating a single user at a time, a list of dicts will be sent for bulk update and creation.
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/backend/sync/_syncers.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/bot/exts/backend/sync/_syncers.py b/bot/exts/backend/sync/_syncers.py index 156c32a15..7d1a8eacc 100644 --- a/bot/exts/backend/sync/_syncers.py +++ b/bot/exts/backend/sync/_syncers.py @@ -367,9 +367,10 @@ class UserSyncer(Syncer): async def _sync(self, diff: _Diff) -> None: """Synchronise the database with the user cache of `guild`.""" log.trace("Syncing created users...") - for user in diff.created: - await self.bot.api_client.post('bot/users', json=user._asdict()) + if diff.created: + created: list = [user._asdict() for user in diff.created] + await self.bot.api_client.post("bot/users", json=created) - log.trace("Syncing updated users...") - for user in diff.updated: - await self.bot.api_client.put(f'bot/users/{user.id}', json=user._asdict()) + if diff.updated: + updated = [user._asdict() for user in diff.created] + await self.bot.api_client.patch("bot/users/bulk_patch", json=updated) |