diff --git a/packages/meta-sort-core/src/api/UnifiedAPIServer.ts b/packages/meta-sort-core/src/api/UnifiedAPIServer.ts index ad252cd..6a64b7f 100644 --- a/packages/meta-sort-core/src/api/UnifiedAPIServer.ts +++ b/packages/meta-sort-core/src/api/UnifiedAPIServer.ts @@ -1198,8 +1198,8 @@ export class UnifiedAPIServer { } try { - const key = `/file/${hashId}/${property}`; - await this.kvClient!.setProperty(key, String(value)); + // Write directly to Redis Hash (not flat keys) + await this.kvClient!.setMetadataProperty(hashId, property, String(value)); return { status: 'ok', @@ -1341,11 +1341,10 @@ export class UnifiedAPIServer { await this.kvClient!.setMetadataFlat(hashId, metadata, ['processingStatus']); } - // Update individual properties + // Update individual properties (write to Redis Hash) if (properties) { for (const [property, value] of Object.entries(properties)) { - const key = `/file/${hashId}/${property}`; - await this.kvClient!.setProperty(key, String(value)); + await this.kvClient!.setMetadataProperty(hashId, property, String(value)); } } diff --git a/packages/meta-sort-core/src/api/api.test.ts b/packages/meta-sort-core/src/api/api.test.ts index 4666f83..4b2ec27 100644 --- a/packages/meta-sort-core/src/api/api.test.ts +++ b/packages/meta-sort-core/src/api/api.test.ts @@ -112,6 +112,13 @@ class MockKVClient implements IKVClient { return entry.get(propertyPath) ?? null; } + async setMetadataProperty(hashId: string, property: string, value: string): Promise { + if (!this.data.has(hashId)) { + this.data.set(hashId, new Map()); + } + this.data.get(hashId)!.set(property, value); + } + async deleteMetadataFlat(hashId: string): Promise { const entry = this.data.get(hashId); const count = entry?.size ?? 0; diff --git a/packages/meta-sort-core/src/kv/IKVClient.ts b/packages/meta-sort-core/src/kv/IKVClient.ts index 6952498..e352ea5 100644 --- a/packages/meta-sort-core/src/kv/IKVClient.ts +++ b/packages/meta-sort-core/src/kv/IKVClient.ts @@ -96,6 +96,11 @@ export interface IKVClient { */ getMetadata(hashId: string, propertyPath: string): Promise; + /** + * Set a single metadata property for a file (writes to Redis Hash) + */ + setMetadataProperty(hashId: string, property: string, value: string): Promise; + /** * Delete all metadata for a file */ diff --git a/packages/meta-sort-core/src/kv/RedisClient.ts b/packages/meta-sort-core/src/kv/RedisClient.ts index ba9108e..cf01140 100644 --- a/packages/meta-sort-core/src/kv/RedisClient.ts +++ b/packages/meta-sort-core/src/kv/RedisClient.ts @@ -298,6 +298,18 @@ export class RedisKVClient implements IKVClient { } } + /** + * Set a single metadata property for a file + * Writes directly to Redis hash field + */ + async setMetadataProperty(hashId: string, property: string, value: string): Promise { + const hashKey = this.buildKey(`file:${hashId}`); + await this.redis.hset(hashKey, property, value); + + // Also ensure the file is in the index + await this.redis.sadd(this.buildKey('file:__index__'), hashId); + } + async deleteMetadataFlat(hashId: string): Promise { const hashKey = this.buildKey(`file:${hashId}`); const fieldCount = await this.redis.hlen(hashKey);