Skip to content

Commit 5c46018

Browse files
dantovskaclaude
andcommitted
fix(vector-search): detect existing keys on any cluster node
The keys endpoint returns one scan result per cluster node, but the existing-keys probe only inspected the first entry. Keys living on any other shard made the create-index page claim the database is empty and enter manual creation. Aggregate the check across all returned nodes. References: #RI-8171 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent a4336a2 commit 5c46018

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

redisinsight/ui/src/pages/vector-search/hooks/useHasExistingKeys/useHasExistingKeys.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ describe('useHasExistingKeys', () => {
5656
expect(result.current.error).toBe(false)
5757
})
5858

59+
it('should detect keys held by any cluster node', async () => {
60+
mockApiPost.mockResolvedValue({
61+
status: 200,
62+
data: [
63+
{ keys: [], total: 0 },
64+
{ keys: [{ name: 'key:1' }], total: 1 },
65+
],
66+
})
67+
68+
const { result, waitForNextUpdate } = renderHook(() => useHasExistingKeys())
69+
70+
await waitForNextUpdate()
71+
72+
expect(result.current.hasKeys).toBe(true)
73+
})
74+
5975
it('should scan with the default scan count', async () => {
6076
mockApiPost.mockResolvedValue({
6177
status: 200,

redisinsight/ui/src/pages/vector-search/hooks/useHasExistingKeys/useHasExistingKeys.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ export const useHasExistingKeys = (): UseHasExistingKeysResult => {
6161

6262
if (signal?.aborted) return
6363

64+
// The endpoint returns one entry per cluster node — check them all
6465
const foundAny = results.some(({ data, status }) => {
6566
if (!isStatusSuccessful(status)) return false
66-
const keys = Array.isArray(data)
67-
? data[0]?.keys
68-
: (data as unknown as ScanResponse)?.keys
69-
return keys && keys.length > 0
67+
const nodes = Array.isArray(data)
68+
? data
69+
: [data as unknown as ScanResponse]
70+
return nodes.some((node) => !!node?.keys?.length)
7071
})
7172

7273
setHasKeys(foundAny)

0 commit comments

Comments
 (0)