mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2026-03-21 20:18:40 -06:00
fix(history-sync): reset cumulative counters on new sync start and abort
Detect new sync runs by tracking lastProgress — when progress resets or decreases, counters are zeroed before accumulating. This prevents stale counts from aborted syncs leaking into subsequent runs. Addresses Sourcery review feedback on PR #2442.
This commit is contained in:
@@ -252,10 +252,11 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
private logBaileys = this.configService.get<Log>('LOG').BAILEYS;
|
||||
private eventProcessingQueue: Promise<void> = Promise.resolve();
|
||||
|
||||
// Cumulative history sync counters (reset on sync completion)
|
||||
// Cumulative history sync counters (reset on new sync or completion)
|
||||
private historySyncMessageCount = 0;
|
||||
private historySyncChatCount = 0;
|
||||
private historySyncContactCount = 0;
|
||||
private historySyncLastProgress = -1;
|
||||
|
||||
// Cache TTL constants (in seconds)
|
||||
private readonly MESSAGE_CACHE_TTL_SECONDS = 5 * 60; // 5 minutes - avoid duplicate message processing
|
||||
@@ -945,6 +946,14 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
syncType?: proto.HistorySync.HistorySyncType;
|
||||
}) => {
|
||||
try {
|
||||
// Reset counters when a new sync starts (progress resets or decreases)
|
||||
if (progress <= this.historySyncLastProgress) {
|
||||
this.historySyncMessageCount = 0;
|
||||
this.historySyncChatCount = 0;
|
||||
this.historySyncContactCount = 0;
|
||||
}
|
||||
this.historySyncLastProgress = progress ?? -1;
|
||||
|
||||
if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
||||
console.log('received on-demand history sync, messages=', messages);
|
||||
}
|
||||
@@ -1093,6 +1102,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
this.historySyncMessageCount = 0;
|
||||
this.historySyncChatCount = 0;
|
||||
this.historySyncContactCount = 0;
|
||||
this.historySyncLastProgress = -1;
|
||||
}
|
||||
|
||||
contacts = undefined;
|
||||
|
||||
Reference in New Issue
Block a user