get total_messages speed up

O(n) -> O(1)
This commit is contained in:
fxxk-research
2025-06-19 20:42:10 +08:00
committed by GitHub
parent 6c98710320
commit 6baf4bdd13

View File

@@ -162,11 +162,8 @@ async def scrape_channel(channel, offset_id):
total_messages = 0 total_messages = 0
processed_messages = 0 processed_messages = 0
async for message in client.iter_messages(entity, offset_id=offset_id, reverse=True): result = await client.get_messages(entity, offset_id=offset_id, reverse=True, limit=0)
sys.stdout.write("\r\033[K") total_messages = result.total
sys.stdout.write(f"Counting messages in: {channel} - Messages found: {total_messages}")
sys.stdout.flush()
total_messages += 1
if total_messages == 0: if total_messages == 0:
print(f"No messages found in channel {channel}.") print(f"No messages found in channel {channel}.")