From 6b50152bb31e80b1e3aacd9288c29e8e3ab404b7 Mon Sep 17 00:00:00 2001
From: Lonami Exo <totufals@hotmail.com>
Date: Wed, 27 Feb 2019 13:07:25 +0100
Subject: [PATCH] Use constants for chunk sizes, remove irrelevant TODO

---
 telethon/client/chats.py   | 13 +++++++++----
 telethon/client/dialogs.py |  4 +++-
 telethon/requestiter.py    |  4 ----
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/telethon/client/chats.py b/telethon/client/chats.py
index cb5263fb..fd8cce14 100644
--- a/telethon/client/chats.py
+++ b/telethon/client/chats.py
@@ -6,6 +6,9 @@ from .. import utils
 from ..requestiter import RequestIter
 from ..tl import types, functions, custom
 
+_MAX_PARTICIPANTS_CHUNK_SIZE = 200
+_MAX_ADMIN_LOG_CHUNK_SIZE = 100
+
 
 class _ParticipantsIter(RequestIter):
     async def _init(self, entity, filter, search, aggressive):
@@ -46,7 +49,7 @@ class _ParticipantsIter(RequestIter):
                     channel=entity,
                     filter=types.ChannelParticipantsSearch(x),
                     offset=0,
-                    limit=200,
+                    limit=_MAX_PARTICIPANTS_CHUNK_SIZE,
                     hash=0
                 ) for x in (search or string.ascii_lowercase)]
             else:
@@ -54,7 +57,7 @@ class _ParticipantsIter(RequestIter):
                     channel=entity,
                     filter=filter or types.ChannelParticipantsSearch(search),
                     offset=0,
-                    limit=200,
+                    limit=_MAX_PARTICIPANTS_CHUNK_SIZE,
                     hash=0
                 )]
 
@@ -100,7 +103,9 @@ class _ParticipantsIter(RequestIter):
         # Most people won't care about getting exactly 12,345
         # members so it doesn't really matter not to be 100%
         # precise with being out of the offset/limit here.
-        self.requests[0].limit = min(self.limit - self.requests[0].offset, 200)
+        self.requests[0].limit = min(
+            self.limit - self.requests[0].offset, _MAX_PARTICIPANTS_CHUNK_SIZE)
+
         if self.requests[0].offset > self.limit:
             return True
 
@@ -157,7 +162,7 @@ class _AdminLogIter(RequestIter):
         )
 
     async def _load_next_chunk(self):
-        self.request.limit = min(self.left, 100)
+        self.request.limit = min(self.left, _MAX_ADMIN_LOG_CHUNK_SIZE)
         r = await self.client(self.request)
         entities = {utils.get_peer_id(x): x
                     for x in itertools.chain(r.users, r.chats)}
diff --git a/telethon/client/dialogs.py b/telethon/client/dialogs.py
index f9782f4d..f17a7223 100644
--- a/telethon/client/dialogs.py
+++ b/telethon/client/dialogs.py
@@ -5,6 +5,8 @@ from .. import utils
 from ..requestiter import RequestIter
 from ..tl import types, functions, custom
 
+_MAX_CHUNK_SIZE = 100
+
 
 class _DialogsIter(RequestIter):
     async def _init(
@@ -29,7 +31,7 @@ class _DialogsIter(RequestIter):
         self.ignore_migrated = ignore_migrated
 
     async def _load_next_chunk(self):
-        self.request.limit = min(self.left, 100)
+        self.request.limit = min(self.left, _MAX_CHUNK_SIZE)
         r = await self.client(self.request)
 
         self.total = getattr(r, 'count', len(r.dialogs))
diff --git a/telethon/requestiter.py b/telethon/requestiter.py
index 111d4509..7fd42fd8 100644
--- a/telethon/requestiter.py
+++ b/telethon/requestiter.py
@@ -5,10 +5,6 @@ import time
 from . import helpers
 
 
-# TODO There are two types of iterators for requests.
-#      One has a limit of items to retrieve, and the
-#      other has a list that must be called in chunks.
-#      Make classes for both here so it's easy to use.
 class RequestIter(abc.ABC):
     """
     Helper class to deal with requests that need offsets to iterate.