aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2024-06-13 15:14:21 +0100
committerGravatar GitHub <[email protected]>2024-06-13 15:14:21 +0100
commit961f5aa2f26f46032def9808f3f1bfb894959ae9 (patch)
tree280caceab6050e7689e14710690fd4da3670f719
parentFix site startup command used in docker-compose.yml (#3093) (diff)
parentMerge branch 'main' into use-itertools-batched (diff)
Merge pull request #3090 from python-discord/use-itertools-batched
Use new `itertools.batched` instead of `more_itertools.chunked`
-rw-r--r--bot/exts/backend/sync/_syncers.py6
-rw-r--r--poetry.lock16
-rw-r--r--pyproject.toml1
-rw-r--r--tests/bot/exts/backend/sync/test_users.py8
4 files changed, 9 insertions, 22 deletions
diff --git a/bot/exts/backend/sync/_syncers.py b/bot/exts/backend/sync/_syncers.py
index e1ed6dff4..88f34e9a8 100644
--- a/bot/exts/backend/sync/_syncers.py
+++ b/bot/exts/backend/sync/_syncers.py
@@ -1,11 +1,11 @@
import abc
import typing as t
from collections import namedtuple
+from itertools import batched
import discord.errors
from discord import Guild
from discord.ext.commands import Context
-from more_itertools import chunked
from pydis_core.site_api import ResponseCodeError
import bot
@@ -225,10 +225,10 @@ class UserSyncer(Syncer):
# Using asyncio.gather would still consume too many resources on the site.
log.trace("Syncing created users...")
if diff.created:
- for chunk in chunked(diff.created, CHUNK_SIZE):
+ for chunk in batched(diff.created, CHUNK_SIZE):
await bot.instance.api_client.post("bot/users", json=chunk)
log.trace("Syncing updated users...")
if diff.updated:
- for chunk in chunked(diff.updated, CHUNK_SIZE):
+ for chunk in batched(diff.updated, CHUNK_SIZE):
await bot.instance.api_client.patch("bot/users/bulk_patch", json=chunk)
diff --git a/poetry.lock b/poetry.lock
index 298dac1c8..0edb89fc2 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1,4 +1,4 @@
-# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.
+# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
[[package]]
name = "aiodns"
@@ -1101,17 +1101,6 @@ beautifulsoup4 = ">=4.9,<5"
six = ">=1.15,<2"
[[package]]
-name = "more-itertools"
-version = "10.2.0"
-description = "More routines for operating on iterables, beyond itertools"
-optional = false
-python-versions = ">=3.8"
-files = [
- {file = "more-itertools-10.2.0.tar.gz", hash = "sha256:8fccb480c43d3e99a00087634c06dd02b0d50fbf088b380de5a41a015ec239e1"},
- {file = "more_itertools-10.2.0-py3-none-any.whl", hash = "sha256:686b06abe565edfab151cb8fd385a05651e1fdf8f0a14191e4439283421f8684"},
-]
-
-[[package]]
name = "mslex"
version = "1.2.0"
description = "shlex for windows"
@@ -1755,7 +1744,6 @@ files = [
{file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"},
{file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"},
{file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"},
- {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"},
{file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"},
{file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"},
{file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"},
@@ -2415,4 +2403,4 @@ multidict = ">=4.0"
[metadata]
lock-version = "2.0"
python-versions = "3.12.*"
-content-hash = "75a40d9b9fa4b42bfe11c34a5ed05b976b3db2a8e37ee388803cf6e5b5995caf"
+content-hash = "2e522a8fd243d9552dd67b9ed12eda4a3a80c4f30939cccc60775a49d74c5e1e"
diff --git a/pyproject.toml b/pyproject.toml
index a6585d590..a375f6219 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -21,7 +21,6 @@ emoji = "2.12.1"
feedparser = "6.0.11"
lxml = "5.2.2"
markdownify = "0.12.1"
-more-itertools = "10.2.0"
python-dateutil = "2.9.0.post0"
python-frontmatter = "1.1.0"
rapidfuzz = "3.9.3"
diff --git a/tests/bot/exts/backend/sync/test_users.py b/tests/bot/exts/backend/sync/test_users.py
index 2fc000446..26bf0d9a0 100644
--- a/tests/bot/exts/backend/sync/test_users.py
+++ b/tests/bot/exts/backend/sync/test_users.py
@@ -210,8 +210,8 @@ class UserSyncerSyncTests(unittest.IsolatedAsyncioTestCase):
diff = _Diff(self.users, [], None)
await UserSyncer._sync(diff)
- self.bot.api_client.post.assert_any_call("bot/users", json=diff.created[:self.chunk_size])
- self.bot.api_client.post.assert_any_call("bot/users", json=diff.created[self.chunk_size:])
+ self.bot.api_client.post.assert_any_call("bot/users", json=tuple(diff.created[:self.chunk_size]))
+ self.bot.api_client.post.assert_any_call("bot/users", json=tuple(diff.created[self.chunk_size:]))
self.assertEqual(self.bot.api_client.post.call_count, self.chunk_count)
self.bot.api_client.put.assert_not_called()
@@ -222,8 +222,8 @@ class UserSyncerSyncTests(unittest.IsolatedAsyncioTestCase):
diff = _Diff([], self.users, None)
await UserSyncer._sync(diff)
- self.bot.api_client.patch.assert_any_call("bot/users/bulk_patch", json=diff.updated[:self.chunk_size])
- self.bot.api_client.patch.assert_any_call("bot/users/bulk_patch", json=diff.updated[self.chunk_size:])
+ self.bot.api_client.patch.assert_any_call("bot/users/bulk_patch", json=tuple(diff.updated[:self.chunk_size]))
+ self.bot.api_client.patch.assert_any_call("bot/users/bulk_patch", json=tuple(diff.updated[self.chunk_size:]))
self.assertEqual(self.bot.api_client.patch.call_count, self.chunk_count)
self.bot.api_client.post.assert_not_called()