Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(session): say the delete runs in batches, then a transaction

Yudhi Armyndharis69606ac5f07d
diff --git a/src/modules/session/session-engine-controls.ts b/src/modules/session/session-engine-controls.ts
index 08c228453..47c1a12ab 100644
--- a/src/modules/session/session-engine-controls.ts
+++ b/src/modules/session/session-engine-controls.ts
@@ -817,7 +817,9 @@ export class SessionEngineControls {
);
// DB removal is NOT best-effort: a genuine failure must surface (500) rather than be swallowed.
- // Delete every child row explicitly, in one transaction, children before the parent. For
+ // Delete every child row explicitly, children before the parent: the three tables that grow with traffic
+ // go first, in batches (a failure part-way keeps the session with fewer rows), then the rest and the
+ // parent in one transaction. For
// messages/message_batches this is load-bearing: they carry a plain sessionId with no FK, so
// nothing else would ever remove them. webhooks/templates/baileys_stored_messages (and
// automation_rules) DO declare an ON DELETE CASCADE FK that fires on BOTH engines —
diff --git a/src/modules/session/session.service.spec.ts b/src/modules/session/session.service.spec.ts
index 7a240e368..6b44c8c5d 100644
--- a/src/modules/session/session.service.spec.ts
+++ b/src/modules/session/session.service.spec.ts
@@ -1356,7 +1356,7 @@ describe('SessionService', () => {
expect(mockEngine.forceDestroy).toHaveBeenCalled();
});
- it('removes the session and all its child rows explicitly in one transaction (SQLite cascade is off)', async () => {
+ it('removes the rest of the child rows and the session explicitly in one transaction after the traffic batches (SQLite cascade is off)', async () => {
const session = createMockSession();
(repository.findOne as jest.Mock).mockResolvedValue(session);