Skip to content

Commit

Permalink
feat: scan queue titles instead of keys search
Browse files Browse the repository at this point in the history
relates: #78
  • Loading branch information
Boris Dorofeev committed Aug 21, 2023
1 parent 22c244b commit 7126f2d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
32 changes: 32 additions & 0 deletions src/helpers/queueTitles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,35 @@ export async function fetchQueueTitles(prefix: string, opts: Options): Promise<A
};
});
}

export async function scanQueueTitles(prefix: string, opts: Options): Promise<Array<Title>> {
const connection = getBullConnection(opts);
const normalizedPrefixGlob = normalizePrefixGlob(prefix);

const result = await new Promise<string[]>((resolve, reject) => {
//redis-cli: scan 0 match bull.vpc:*:meta count 100000
const stream = connection.scanStream({ match: normalizedPrefixGlob, count: 100000 });

const titles: string[] = [];

stream.on('data', async (keys) => {
for (let i = 0; i < keys.length; i++) {
titles.push(keys[i]);
}
});

stream.on('end', () => {
resolve(titles);
});

stream.on('error', reject);
});

return result.map((key) => {
const parts = key.split(':');
return {
prefix: parts.slice(0, -2).join(':'),
queueName: parts[parts.length - 2],
};
});
}
4 changes: 2 additions & 2 deletions src/query/queueKeys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SchemaComposer, ObjectTypeComposerFieldConfigAsObjectDefinition } from 'graphql-compose';
import { fetchQueueTitles } from '../helpers';
import { scanQueueTitles } from '../helpers';
import { Options } from '../definitions';

export function createQueueKeysFC(
Expand All @@ -22,7 +22,7 @@ export function createQueueKeysFC(
},
},
resolve: async (_, { prefixGlob }) => {
return fetchQueueTitles(prefixGlob, opts);
return scanQueueTitles(prefixGlob, opts);
},
};
}
4 changes: 2 additions & 2 deletions src/query/queues.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SchemaComposer, ObjectTypeComposerFieldConfigAsObjectDefinition } from 'graphql-compose';
import { getQueueTC } from '../types/queue/Queue';
import { fetchQueueTitles, getQueues } from '../helpers';
import { scanQueueTitles, getQueues } from '../helpers';
import { Options } from '../definitions';

export function createQueuesFC(
Expand All @@ -16,7 +16,7 @@ export function createQueuesFC(
},
},
resolve: async (_, { prefix }) => {
const titles = await fetchQueueTitles(prefix, opts);
const titles = await scanQueueTitles(prefix, opts);
return getQueues(titles, opts);
},
};
Expand Down

0 comments on commit 7126f2d

Please sign in to comment.