mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
fix(plugins): hold the write lock for the plugin cap checks on Postgres
meta.set and scheduler.set checked their caps in a transaction of the repository's own, which keeps check and write together on SQLite's single writer but not on Postgres, where two pool connections both read the same count. Both RPCs now run the capped write inside UnitOfWork.transactional, which takes the engine's write lock; the repository's transaction becomes a savepoint of it.
This commit is contained in:
@@ -641,6 +641,7 @@ export async function createPluginRpcHostParts(
|
||||
await createTestDaysRepo(db),
|
||||
await createTestReservationsRepo(db),
|
||||
await createTestDayAccommodationsRepo(db),
|
||||
await createTestUnitOfWork(db),
|
||||
),
|
||||
// Plan 3j Task 5 — HostSurfaceRpc's own HR1/HR5–HR9 conversion: the plugin-visible
|
||||
// user row, the bilateral trip-sharing gate, and its own scheduler.set/cancel.
|
||||
@@ -655,6 +656,7 @@ export async function createPluginRpcHostParts(
|
||||
usersRepo,
|
||||
await createTestTripsRepo(db),
|
||||
pluginOrm.repo(PluginScheduledTasks),
|
||||
await createTestUnitOfWork(db),
|
||||
),
|
||||
new PluginHooks(undefined as never),
|
||||
];
|
||||
|
||||
@@ -94,7 +94,16 @@ export function allRpcControllers(): object[] {
|
||||
// Plan 3j Task 5 — MetaRpc/HostSurfaceRpc's own repository conversions (MR#/HR#).
|
||||
// Plan 4 Task 2 — both classes' own DatabaseService param is gone (canAccessTrip
|
||||
// now reads through the TripsRepository they already inject), one fewer anyService().
|
||||
new MetaRpc(anyService(), anyService(), anyService(), anyService(), anyService(), anyService(), anyService()),
|
||||
new MetaRpc(
|
||||
anyService(),
|
||||
anyService(),
|
||||
anyService(),
|
||||
anyService(),
|
||||
anyService(),
|
||||
anyService(),
|
||||
anyService(),
|
||||
anyService(),
|
||||
),
|
||||
new HostSurfaceRpc(
|
||||
anyService(),
|
||||
anyService(),
|
||||
@@ -105,6 +114,7 @@ export function allRpcControllers(): object[] {
|
||||
anyService(),
|
||||
anyService(),
|
||||
anyService(),
|
||||
anyService(),
|
||||
),
|
||||
// Owns no wire method, but declares all 18 hook contracts, which requireTotalCoverage checks too.
|
||||
new PluginHooks(anyService()),
|
||||
|
||||
@@ -22,6 +22,7 @@ import { PluginGuards } from '../../../src/nest-rpc/plugin-guards.service';
|
||||
import { PluginRpcRegistryService } from '../../../src/nest-rpc/rpc-kit/registry.service';
|
||||
import { createTestPluginRegistry } from '../../../src/nest-rpc/rpc-kit/testing';
|
||||
import type { AddonsService } from '../../../src/nest/addons/addons.service';
|
||||
import type { UnitOfWork } from '../../../src/nest/database/unit-of-work';
|
||||
import { UnreadableLlmResponse } from '../../../src/nest/llm-parse/clients/openai-compatible.client';
|
||||
import type { LlmConfigResolver } from '../../../src/nest/llm-parse/llm-config.resolver';
|
||||
import type { NotificationsService } from '../../../src/nest/notifications/notifications.service';
|
||||
@@ -397,9 +398,11 @@ const usersRepo = {
|
||||
// params are gone: canAccessTrip now reads through the TripsRepository each
|
||||
// already injects (`tripsRepo` above, findAccessible-only).
|
||||
const guards = new PluginGuards(tripsRepo, permissions, addons, usersRepo);
|
||||
/** The capped writes run in a unit of work; the stand-in repositories here are atomic on their own. */
|
||||
const uow = { transactional: <T>(fn: () => Promise<T>) => fn() } as unknown as UnitOfWork;
|
||||
const registry = createTestPluginRegistry([
|
||||
new DbRpc(userSettings),
|
||||
new MetaRpc(guards, metaRepo, tripsRepo, placesRepo, daysRepo, reservationsRepo, dayAccommodationsRepo),
|
||||
new MetaRpc(guards, metaRepo, tripsRepo, placesRepo, daysRepo, reservationsRepo, dayAccommodationsRepo, uow),
|
||||
new HostSurfaceRpc(
|
||||
realtime,
|
||||
notifications,
|
||||
@@ -410,6 +413,7 @@ const registry = createTestPluginRegistry([
|
||||
usersRepo,
|
||||
tripsRepo,
|
||||
scheduledTasksRepo,
|
||||
uow,
|
||||
),
|
||||
]);
|
||||
const factory = new PluginRpcHostFactory(pluginAuditRepo, registry as unknown as PluginRpcRegistryService);
|
||||
|
||||
Reference in New Issue
Block a user