Skip to content

Commit c46563a

Browse files
committed
refactor(webapp): move the postgres task-event write guard to the repository entry points
Guarding at TaskEventStore.createMany stopped the write but the repository still buffered, reported success, and published Redis notifications for events that were never persisted. Move the check to the insertMany/insertImmediate/ insertManyImmediate entry points so the postgres store is fully inert when writes are disabled.
1 parent a29dd59 commit c46563a

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

apps/webapp/app/v3/eventRepository/eventRepository.server.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,7 @@ export class EventRepository implements IEventRepository {
120120
this._tracer = _config.tracer ?? trace.getTracer("eventRepo", "0.0.1");
121121

122122
// Instantiate the store using the partitioning flag.
123-
this.taskEventStore = new TaskEventStore(
124-
db,
125-
readReplica,
126-
env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED
127-
);
123+
this.taskEventStore = new TaskEventStore(db, readReplica);
128124
}
129125

130126
#createableEventToPrismaEvent(event: CreateEventInput): Prisma.TaskEventCreateManyInput {
@@ -161,14 +157,23 @@ export class EventRepository implements IEventRepository {
161157
}
162158

163159
private async insertImmediate(event: CreateEventInput) {
160+
if (env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED) {
161+
return;
162+
}
164163
await this.#flushBatch(nanoid(), [this.#createableEventToPrismaEvent(event)]);
165164
}
166165

167166
insertMany(events: CreateEventInput[]) {
167+
if (env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED) {
168+
return;
169+
}
168170
this._flushScheduler.addToBatch(events.map(this.#createableEventToPrismaEvent));
169171
}
170172

171173
async insertManyImmediate(events: CreateEventInput[]) {
174+
if (env.EVENT_REPOSITORY_POSTGRES_WRITES_DISABLED) {
175+
return;
176+
}
172177
await this.#flushBatchWithReturn(nanoid(), events.map(this.#createableEventToPrismaEvent));
173178
}
174179

apps/webapp/app/v3/taskEventStore.server.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,13 @@ export function getTaskEventStore(): TaskEventStoreTable {
5959
export class TaskEventStore {
6060
constructor(
6161
private db: PrismaClient,
62-
private readReplica: PrismaReplicaClient,
63-
private writesDisabled: boolean = false
62+
private readReplica: PrismaReplicaClient
6463
) {}
6564

6665
/**
6766
* Insert one record.
6867
*/
6968
async create(table: TaskEventStoreTable, data: Prisma.TaskEventCreateInput) {
70-
if (this.writesDisabled) {
71-
return;
72-
}
7369
if (table === "taskEventPartitioned") {
7470
return await this.db.taskEventPartitioned.create({ data });
7571
} else {
@@ -81,9 +77,6 @@ export class TaskEventStore {
8177
* Insert many records.
8278
*/
8379
async createMany(table: TaskEventStoreTable, data: Prisma.TaskEventCreateManyInput[]) {
84-
if (this.writesDisabled) {
85-
return { count: 0 };
86-
}
8780
if (table === "taskEventPartitioned") {
8881
return await this.db.taskEventPartitioned.createMany({ data });
8982
} else {

0 commit comments

Comments
 (0)