From 4f38c61725313fac64d3b7e5806ea4b4557f4c98 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Sun, 19 Apr 2026 22:05:56 +0100 Subject: [PATCH] fix(server): avoid acquiring redis client when base query cache is disabled --- .../base-query-cache.write-consumer.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/server/src/core/base/query-cache/base-query-cache.write-consumer.ts b/apps/server/src/core/base/query-cache/base-query-cache.write-consumer.ts index cc95b1d8..83198a04 100644 --- a/apps/server/src/core/base/query-cache/base-query-cache.write-consumer.ts +++ b/apps/server/src/core/base/query-cache/base-query-cache.write-consumer.ts @@ -28,14 +28,17 @@ import { ChangeEnvelope } from './query-cache.types'; @Injectable() export class BaseQueryCacheWriteConsumer { private readonly logger = new Logger(BaseQueryCacheWriteConsumer.name); - private readonly redis: Redis; + private _redis: Redis | null = null; constructor( private readonly redisService: RedisService, private readonly configProvider: QueryCacheConfigProvider, private readonly baseRowRepo: BaseRowRepo, - ) { - this.redis = this.redisService.getOrThrow(); + ) {} + + private get redis(): Redis { + if (!this._redis) this._redis = this.redisService.getOrThrow(); + return this._redis; } @OnEvent(EventName.BASE_ROW_CREATED) @@ -116,9 +119,11 @@ export class BaseQueryCacheWriteConsumer { @OnEvent(EventName.BASE_PROPERTY_CREATED) async onPropertyCreated(e: BasePropertyCreatedEvent): Promise { if (!this.configProvider.config.enabled) return; - // Property creation doesn't carry a schemaVersion in its payload; use 0 - // so applyChange always treats it as stale relative to the resident - // collection (which has schemaVersion >= 1) and triggers invalidation. + // Property CREATED / DELETED events don't carry a schemaVersion. Use + // Number.MAX_SAFE_INTEGER as a sentinel so `applyChange`'s + // `envVersion > cachedVersion` check unconditionally invalidates — any + // real schemaVersion will be smaller. A follow-up could plumb the real + // schemaVersion through the event payload and drop the sentinel. await this.publish(e.baseId, { kind: 'schema-invalidate', baseId: e.baseId,