From 22da4dfad29d8b06849ac86fa1eff1df8045f80f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Mar 2026 08:36:40 +0000 Subject: [PATCH] Fix messagesScanned consistency: use totalScanned from scan results, remove double-counting Co-authored-by: xCyanGrizzly <53275238+xCyanGrizzly@users.noreply.github.com> --- worker/src/tdlib/download.ts | 2 ++ worker/src/tdlib/topics.ts | 1 + worker/src/worker.ts | 7 ++----- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/worker/src/tdlib/download.ts b/worker/src/tdlib/download.ts index c405c55..0597ae3 100644 --- a/worker/src/tdlib/download.ts +++ b/worker/src/tdlib/download.ts @@ -66,6 +66,7 @@ interface TdFile { export interface ChannelScanResult { archives: TelegramMessage[]; photos: TelegramPhoto[]; + totalScanned: number; } export type ScanProgressCallback = (messagesScanned: number) => void; @@ -161,6 +162,7 @@ export async function getChannelMessages( return { archives: archives.reverse(), photos: photos.reverse(), + totalScanned, }; } diff --git a/worker/src/tdlib/topics.ts b/worker/src/tdlib/topics.ts index 1c8e7ce..107bf37 100644 --- a/worker/src/tdlib/topics.ts +++ b/worker/src/tdlib/topics.ts @@ -245,6 +245,7 @@ export async function getTopicMessages( return { archives: archives.reverse(), photos: photos.reverse(), + totalScanned, }; } diff --git a/worker/src/worker.ts b/worker/src/worker.ts index e77c4e4..e61c64c 100644 --- a/worker/src/worker.ts +++ b/worker/src/worker.ts @@ -448,8 +448,7 @@ export async function runWorkerForAccount( ); // Add scanned messages to global counter - const topicMsgCount = scanResult.archives.length + scanResult.photos.length; - counters.messagesScanned += topicMsgCount; + counters.messagesScanned += scanResult.totalScanned; if (scanResult.archives.length === 0) { accountLog.debug( @@ -523,8 +522,7 @@ export async function runWorkerForAccount( ); // Add scanned messages to global counter - const channelMsgCount = scanResult.archives.length + scanResult.photos.length; - counters.messagesScanned += channelMsgCount; + counters.messagesScanned += scanResult.totalScanned; if (scanResult.archives.length === 0) { accountLog.debug({ channelId: channel.id }, "No new archives"); @@ -688,7 +686,6 @@ async function processOneArchiveSet( throttled, counters, topicCreator, sourceTopicId, accountLog, } = ctx; - counters.messagesScanned += archiveSet.parts.length; const archiveName = archiveSet.parts[0].fileName; // ── Early skip: check if this archive set was already ingested ──