@@ -20,6 +20,7 @@ import {
2020} from "~/db.server" ;
2121import { env } from "~/env.server" ;
2222import { singleton } from "~/utils/singleton" ;
23+ import { isSnapshotStoreConfigured } from "./snapshotStoreConfigured.server" ;
2324import { decorateWithSnapshotStore } from "./snapshotStoreInstance.server" ;
2425import { snapshotStoreModeResolver } from "./snapshotStoreMode.server" ;
2526import {
@@ -55,15 +56,20 @@ type BuildRunStoreDeps = {
5556 singleResilience ?: TransactionResilienceConfig ;
5657 newResilience ?: TransactionResilienceConfig ;
5758 legacyResilience ?: TransactionResilienceConfig ;
59+ /** The redis-only PG-suppression predicate, or undefined for a plain passthrough. Passed in (never
60+ * read from env here) so this builder stays pure; the caller wires it only when the store is
61+ * configured, so an unconfigured deploy writes every snapshot row with no per-write resolution. */
62+ snapshotWrites ?: ( organizationId ?: string ) => boolean ;
5863} ;
5964
6065/**
6166 * Pure run-store builder (no env / no boot side effects — webapp testability rule).
6267 *
6368 * Split OFF (default / self-host): returns the exact passthrough PostgresRunStore we
6469 * have always returned, built from the single control-plane handles. No second store
65- * is constructed and no marker predicate is consulted, so behavior is byte-identical
66- * to single-DB today.
70+ * is constructed, and the redis-only marker predicate is consulted only when the caller
71+ * wired one (i.e. the snapshot store is configured); with it unset behavior is
72+ * byte-identical to single-DB today.
6773 *
6874 * Split ON: returns a RoutingRunStore that selects between a NEW store (where new runs
6975 * are born) and a LEGACY store (draining) by run-id residency (id shape). There is no cuid
@@ -74,14 +80,18 @@ type BuildRunStoreDeps = {
7480const suppressPgAtRedisOnly = ( organizationId ?: string ) =>
7581 snapshotStoreModeResolver . resolve ( organizationId ) !== "redis-only" ;
7682
83+ // Wired into the store only when the snapshot store is configured. Unconfigured, this stays undefined
84+ // and PostgresRunStore writes every snapshot row with no per-write mode resolution (the inert state).
85+ const snapshotWritesPredicate = isSnapshotStoreConfigured ( ) ? suppressPgAtRedisOnly : undefined ;
86+
7787export function buildRunStore ( deps : BuildRunStoreDeps ) : RunStore {
7888 if ( ! deps . splitEnabled ) {
7989 return new PostgresRunStore ( {
8090 prisma : deps . singleWriter ,
8191 readOnlyPrisma : deps . singleReplica ,
8292 maxWait : deps . singleResilience ?. maxWait ,
8393 transactionStartRetry : deps . singleResilience ?. startRetry ,
84- snapshotWrites : suppressPgAtRedisOnly ,
94+ snapshotWrites : deps . snapshotWrites ,
8595 } ) ;
8696 }
8797
@@ -97,14 +107,14 @@ export function buildRunStore(deps: BuildRunStoreDeps): RunStore {
97107 schemaVariant : "dedicated" ,
98108 maxWait : deps . newResilience ?. maxWait ,
99109 transactionStartRetry : deps . newResilience ?. startRetry ,
100- snapshotWrites : suppressPgAtRedisOnly ,
110+ snapshotWrites : deps . snapshotWrites ,
101111 } ) ;
102112 const legacyStore = new PostgresRunStore ( {
103113 prisma : deps . legacyWriter ,
104114 readOnlyPrisma : deps . legacyReplica ,
105115 maxWait : deps . legacyResilience ?. maxWait ,
106116 transactionStartRetry : deps . legacyResilience ?. startRetry ,
107- snapshotWrites : suppressPgAtRedisOnly ,
117+ snapshotWrites : deps . snapshotWrites ,
108118 } ) ;
109119
110120 // Gen-2 shards: one dedicated store per descriptor, handed to the N-way router. An aliased shard
@@ -118,7 +128,7 @@ export function buildRunStore(deps: BuildRunStoreDeps): RunStore {
118128 schemaVariant : "dedicated" as const ,
119129 maxWait : shard . resilience ?. maxWait ,
120130 transactionStartRetry : shard . resilience ?. startRetry ,
121- snapshotWrites : suppressPgAtRedisOnly ,
131+ snapshotWrites : deps . snapshotWrites ,
122132 } ) ,
123133 aliasOf : shard . aliasOf ,
124134 } ) ) ;
@@ -198,6 +208,7 @@ export const runStoreWithoutSnapshotDecorator: RunStore = singleton("RunStore.un
198208 singleWriter : prisma ,
199209 singleReplica : $replica ,
200210 singleResilience : resilienceForClient ( prisma ) ,
211+ snapshotWrites : snapshotWritesPredicate ,
201212 } ) ;
202213 }
203214 const { shardHandles, ...storeHandles } = handles ;
@@ -216,6 +227,7 @@ export const runStoreWithoutSnapshotDecorator: RunStore = singleton("RunStore.un
216227 singleResilience : resilienceForClient ( prisma ) ,
217228 newResilience : resilienceForClient ( handles . newWriter ) ,
218229 legacyResilience : resilienceForClient ( handles . legacyWriter ) ,
230+ snapshotWrites : snapshotWritesPredicate ,
219231 } ) ;
220232} ) ;
221233
0 commit comments