mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-22 10:54:15 +03:00
Use constants for chunk sizes, remove irrelevant TODO
This commit is contained in:
parent
d02d0e2d5e
commit
6b50152bb3
|
@ -6,6 +6,9 @@ from .. import utils
|
||||||
from ..requestiter import RequestIter
|
from ..requestiter import RequestIter
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions, custom
|
||||||
|
|
||||||
|
_MAX_PARTICIPANTS_CHUNK_SIZE = 200
|
||||||
|
_MAX_ADMIN_LOG_CHUNK_SIZE = 100
|
||||||
|
|
||||||
|
|
||||||
class _ParticipantsIter(RequestIter):
|
class _ParticipantsIter(RequestIter):
|
||||||
async def _init(self, entity, filter, search, aggressive):
|
async def _init(self, entity, filter, search, aggressive):
|
||||||
|
@ -46,7 +49,7 @@ class _ParticipantsIter(RequestIter):
|
||||||
channel=entity,
|
channel=entity,
|
||||||
filter=types.ChannelParticipantsSearch(x),
|
filter=types.ChannelParticipantsSearch(x),
|
||||||
offset=0,
|
offset=0,
|
||||||
limit=200,
|
limit=_MAX_PARTICIPANTS_CHUNK_SIZE,
|
||||||
hash=0
|
hash=0
|
||||||
) for x in (search or string.ascii_lowercase)]
|
) for x in (search or string.ascii_lowercase)]
|
||||||
else:
|
else:
|
||||||
|
@ -54,7 +57,7 @@ class _ParticipantsIter(RequestIter):
|
||||||
channel=entity,
|
channel=entity,
|
||||||
filter=filter or types.ChannelParticipantsSearch(search),
|
filter=filter or types.ChannelParticipantsSearch(search),
|
||||||
offset=0,
|
offset=0,
|
||||||
limit=200,
|
limit=_MAX_PARTICIPANTS_CHUNK_SIZE,
|
||||||
hash=0
|
hash=0
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
@ -100,7 +103,9 @@ class _ParticipantsIter(RequestIter):
|
||||||
# Most people won't care about getting exactly 12,345
|
# Most people won't care about getting exactly 12,345
|
||||||
# members so it doesn't really matter not to be 100%
|
# members so it doesn't really matter not to be 100%
|
||||||
# precise with being out of the offset/limit here.
|
# 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:
|
if self.requests[0].offset > self.limit:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -157,7 +162,7 @@ class _AdminLogIter(RequestIter):
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _load_next_chunk(self):
|
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)
|
r = await self.client(self.request)
|
||||||
entities = {utils.get_peer_id(x): x
|
entities = {utils.get_peer_id(x): x
|
||||||
for x in itertools.chain(r.users, r.chats)}
|
for x in itertools.chain(r.users, r.chats)}
|
||||||
|
|
|
@ -5,6 +5,8 @@ from .. import utils
|
||||||
from ..requestiter import RequestIter
|
from ..requestiter import RequestIter
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions, custom
|
||||||
|
|
||||||
|
_MAX_CHUNK_SIZE = 100
|
||||||
|
|
||||||
|
|
||||||
class _DialogsIter(RequestIter):
|
class _DialogsIter(RequestIter):
|
||||||
async def _init(
|
async def _init(
|
||||||
|
@ -29,7 +31,7 @@ class _DialogsIter(RequestIter):
|
||||||
self.ignore_migrated = ignore_migrated
|
self.ignore_migrated = ignore_migrated
|
||||||
|
|
||||||
async def _load_next_chunk(self):
|
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)
|
r = await self.client(self.request)
|
||||||
|
|
||||||
self.total = getattr(r, 'count', len(r.dialogs))
|
self.total = getattr(r, 'count', len(r.dialogs))
|
||||||
|
|
|
@ -5,10 +5,6 @@ import time
|
||||||
from . import helpers
|
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):
|
class RequestIter(abc.ABC):
|
||||||
"""
|
"""
|
||||||
Helper class to deal with requests that need offsets to iterate.
|
Helper class to deal with requests that need offsets to iterate.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user