Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(stats): stop writing a session-stats cache nothing reads

Yudhi Armyndharis00c955b1d81a
diff --git a/src/database/postgres-utc.pg.spec.ts b/src/database/postgres-utc.pg.spec.ts
index 010dda31e..ec75f9f11 100644
--- a/src/database/postgres-utc.pg.spec.ts
+++ b/src/database/postgres-utc.pg.spec.ts
@@ -406,12 +406,7 @@ const SqliteSession = new EntitySchema<Record<string, unknown>>({
);
}
- const stats = new StatsService(
- ds.getRepository(Session),
- messages,
- { setSessionsStats: () => Promise.resolve(undefined) } as never,
- cfg as never,
- );
+ const stats = new StatsService(ds.getRepository(Session), messages, cfg as never);
expect((await stats.getOverview()).messages.today).toEqual({ sent: 1, received: 0 });
});
diff --git a/src/modules/stats/stats.service.spec.ts b/src/modules/stats/stats.service.spec.ts
index 86b414345..42bef0b52 100644
--- a/src/modules/stats/stats.service.spec.ts
+++ b/src/modules/stats/stats.service.spec.ts
@@ -42,9 +42,8 @@ describe('StatsService time-series + hourly activity on SQLite (end-to-end regre
synchronize: true,
});
await ds.initialize();
- const cache = { setSessionsStats: jest.fn() };
const config = { get: () => 30000 };
- service = new StatsService(ds.getRepository(Session), ds.getRepository(Message), cache as never, config as never);
+ service = new StatsService(ds.getRepository(Session), ds.getRepository(Message), config as never);
});
afterEach(async () => {
@@ -310,12 +309,7 @@ describe('StatsService aggregate memo (in-process TTL)', () => {
});
const makeService = (ttlMs: number) =>
- new StatsService(
- ds.getRepository(Session),
- ds.getRepository(Message),
- { setSessionsStats: jest.fn() } as never,
- { get: () => ttlMs } as never,
- );
+ new StatsService(ds.getRepository(Session), ds.getRepository(Message), { get: () => ttlMs } as never);
it('serves a repeated identical call from the memo within the TTL (no second DB hit)', async () => {
const service = makeService(30000);
diff --git a/src/modules/stats/stats.service.ts b/src/modules/stats/stats.service.ts
index ac6a294ec..c386366a0 100644
--- a/src/modules/stats/stats.service.ts
+++ b/src/modules/stats/stats.service.ts
@@ -4,7 +4,6 @@ import { ConfigService } from '@nestjs/config';
import { Repository } from 'typeorm';
import { Session, SessionStatus } from '../session/entities/session.entity';
import { Message, MessageDirection, MessageStatus } from '../message/entities/message.entity';
-import { CacheService } from '../../common/cache';
/**
* SQL for the time-series timestamp bucket, per DB dialect. SQLite has strftime(); Postgres has
@@ -105,7 +104,6 @@ export class StatsService {
private readonly sessionRepo: Repository<Session>,
@InjectRepository(Message, 'data')
private readonly messageRepo: Repository<Message>,
- private readonly cacheService: CacheService,
private readonly configService: ConfigService,
) {}
@@ -193,13 +191,6 @@ export class StatsService {
where: { status: MessageStatus.FAILED },
});
- // Cache session stats
- await this.cacheService.setSessionsStats({
- active,
- total: sessions.length,
- byStatus,
- });
-
return {
sessions: {
active,