Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

perf(api): stop ledgering session payment reconciliation (#2889)

Hampus412a1ae79dd9
diff --git a/fluxer_api/src/api/rpc/RpcService.ts b/fluxer_api/src/api/rpc/RpcService.ts
index b11e9c25d..a479556fc 100644
--- a/fluxer_api/src/api/rpc/RpcService.ts
+++ b/fluxer_api/src/api/rpc/RpcService.ts
@@ -864,7 +864,7 @@ export class RpcService {
if (!queueAllowed) {
return;
}
- await this.workerService.addJob('reconcileUserPayments', {userId: userIdString});
+ await this.workerService.addJob('reconcileUserPayments', {userId: userIdString}, {skipLedger: true});
})
.catch((error) => {
Logger.warn(
diff --git a/fluxer_api/src/api/rpc/tests/RpcSessionPaymentReconciliation.test.ts b/fluxer_api/src/api/rpc/tests/RpcSessionPaymentReconciliation.test.ts
new file mode 100644
index 000000000..932d0aa4a
--- /dev/null
+++ b/fluxer_api/src/api/rpc/tests/RpcSessionPaymentReconciliation.test.ts
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {createTestUserWithPremium} from '@app/api/stripe/tests/StripeWebhookTestUtils';
+import {type ApiTestHarness, createApiTestHarness} from '@app/api/test/ApiTestHarness';
+import {NoopWorkerService} from '@app/api/test/NoopWorkerService';
+import {HTTP_STATUS} from '@app/api/test/TestConstants';
+import {createBuilder} from '@app/api/test/TestRequestBuilder';
+import {UserPremiumTypes} from '@fluxer/constants/src/UserConstants';
+import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest';
+
+describe('RpcService session payment reconciliation', () => {
+ let harness: ApiTestHarness;
+ beforeEach(async () => {
+ harness = await createApiTestHarness();
+ });
+ afterEach(async () => {
+ await harness?.shutdown();
+ });
+ test('queues payment reconciliation without a job record', async () => {
+ const account = await createTestUserWithPremium(harness, UserPremiumTypes.SUBSCRIPTION, {
+ stripeCustomerId: 'cus_rpc_session_reconcile',
+ });
+ const addJob = vi.spyOn(NoopWorkerService.prototype, 'addJob');
+ try {
+ await createBuilder(harness, '')
+ .post('/test/rpc-session-init')
+ .body({type: 'session', token: account.token, version: 1, ip: '127.0.0.1'})
+ .expect(HTTP_STATUS.OK)
+ .execute();
+ await vi.waitFor(() =>
+ expect(addJob).toHaveBeenCalledWith('reconcileUserPayments', {userId: account.userId}, {skipLedger: true}),
+ );
+ } finally {
+ addJob.mockRestore();
+ }
+ });
+});
diff --git a/fluxer_docs/src/content/docs/admin-api/jobs.mdx b/fluxer_docs/src/content/docs/admin-api/jobs.mdx
index 863917985..11458a9d2 100644
--- a/fluxer_docs/src/content/docs/admin-api/jobs.mdx
+++ b/fluxer_docs/src/content/docs/admin-api/jobs.mdx
@@ -11,7 +11,7 @@ These routes list recorded background jobs and request cancellation. Create jobs
Reads require `jobs:view` and cancellation requires `jobs:cancel`. Every operation on this page shares the `admin:jobs:view` bucket. The three reads record no [Admin audit entry](/admin-api/#admin-audit-entry-object), and cancellation records one.
:::note[Job updates vary by task]
-Mention processing, link previews, message delete audit log batching, and every scheduled task except `syncDisposableEmailDomains`, `syncUrlBlocklists` and `syncFileShaBlocklists` run with no job record and never appear here. Fluxer deletes a job record about 90 days after the job was queued. A job also runs with no record when Fluxer fails to write that record. When a later write of status, progress or attempts fails, Fluxer logs the failure and the job continues, so the stored values can be behind the real run. Use the [archive routes](/admin-api/archives/) to track archive progress and failures.
+Mention processing, link previews, message delete audit log batching, payment reconciliation when a user connects, and every scheduled task except `syncDisposableEmailDomains`, `syncUrlBlocklists` and `syncFileShaBlocklists` run with no job record and never appear here. Fluxer deletes a job record about 90 days after the job was queued. A job also runs with no record when Fluxer fails to write that record. When a later write of status, progress or attempts fails, Fluxer logs the failure and the job continues, so the stored values can be behind the real run. Use the [archive routes](/admin-api/archives/) to track archive progress and failures.
:::
## Admin job object