mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-04 05:34:41 +03:00
Don't call getFullChannel during iter_participants unless necessary
This should reduce the floodwaits of this request by a lot.
This commit is contained in:
parent
1e09e133e3
commit
2df1dd7215
|
@ -124,11 +124,11 @@ class _ParticipantsIter(RequestIter):
|
||||||
self.requests = []
|
self.requests = []
|
||||||
|
|
||||||
if ty == helpers._EntityType.CHANNEL:
|
if ty == helpers._EntityType.CHANNEL:
|
||||||
|
if self.limit <= 0:
|
||||||
|
# May not have access to the channel, but getFull can get the .total.
|
||||||
self.total = (await self.client(
|
self.total = (await self.client(
|
||||||
functions.channels.GetFullChannelRequest(entity)
|
functions.channels.GetFullChannelRequest(entity)
|
||||||
)).full_chat.participants_count
|
)).full_chat.participants_count
|
||||||
|
|
||||||
if self.limit <= 0:
|
|
||||||
raise StopAsyncIteration
|
raise StopAsyncIteration
|
||||||
|
|
||||||
self.seen = set()
|
self.seen = set()
|
||||||
|
@ -201,9 +201,29 @@ class _ParticipantsIter(RequestIter):
|
||||||
if self.requests[0].offset > self.limit:
|
if self.requests[0].offset > self.limit:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if self.total is None:
|
||||||
|
f = self.requests[0].filter
|
||||||
|
if len(self.requests) > 1 or (
|
||||||
|
not isinstance(f, types.ChannelParticipantsRecent)
|
||||||
|
and (not isinstance(f, types.ChannelParticipantsSearch) or f.q)
|
||||||
|
):
|
||||||
|
# Only do an additional getParticipants here to get the total
|
||||||
|
# if there's a filter which would reduce the real total number.
|
||||||
|
# getParticipants is cheaper than getFull.
|
||||||
|
self.total = (await self.client(functions.channels.GetParticipantsRequest(
|
||||||
|
channel=self.requests[0].channel,
|
||||||
|
filter=types.ChannelParticipantsRecent(),
|
||||||
|
offset=0,
|
||||||
|
limit=1,
|
||||||
|
hash=0
|
||||||
|
))).count
|
||||||
|
|
||||||
results = await self.client(self.requests)
|
results = await self.client(self.requests)
|
||||||
for i in reversed(range(len(self.requests))):
|
for i in reversed(range(len(self.requests))):
|
||||||
participants = results[i]
|
participants = results[i]
|
||||||
|
if self.total is None:
|
||||||
|
# Will only get here if there was one request with a filter that matched all users.
|
||||||
|
self.total = participants.count
|
||||||
if not participants.users:
|
if not participants.users:
|
||||||
self.requests.pop(i)
|
self.requests.pop(i)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue
Block a user