Skip to content

Commit 28bbb41

Browse files
author
Artem
committed
scan in lower batches for tree-view
1 parent a282105 commit 28bbb41

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

redisinsight/api/src/modules/browser/services/keys-business/scanner/strategies/standalone.strategy.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,40 @@ describe('Standalone Scanner Strategy', () => {
101101
null,
102102
);
103103
});
104+
it('should scan 2000 items when count provided more then 2k', async () => {
105+
const args = { ...getKeysDto, count: 10_000, match: '*' };
106+
jest.spyOn(Utils, 'getTotal').mockResolvedValue(mockGetTotalResponse_1);
107+
108+
when(browserTool.execCommand)
109+
.calledWith(
110+
mockBrowserClientMetadata,
111+
BrowserToolKeysCommands.Scan,
112+
expect.anything(),
113+
null,
114+
)
115+
.mockResolvedValue([0, [getKeyInfoResponse.name]]);
116+
117+
strategy.getKeysInfo = jest.fn().mockResolvedValue([getKeyInfoResponse]);
118+
119+
const result = await strategy.getKeys(mockBrowserClientMetadata, args);
120+
121+
expect(result).toEqual([
122+
{
123+
...mockNodeEmptyResult,
124+
total: 1,
125+
scanned: 2000,
126+
keys: [getKeyInfoResponse],
127+
},
128+
]);
129+
expect(strategy.getKeysInfo).toHaveBeenCalled();
130+
expect(browserTool.execCommand).toHaveBeenNthCalledWith(
131+
1,
132+
mockBrowserClientMetadata,
133+
BrowserToolKeysCommands.Scan,
134+
['0', 'MATCH', args.match, 'COUNT', 2000],
135+
null,
136+
);
137+
});
104138
it('should return keys names and type only', async () => {
105139
const args = {
106140
...getKeysDto, type: 'string', match: 'pattern*', keysInfo: false,

redisinsight/api/src/modules/browser/services/keys-business/scanner/strategies/standalone.strategy.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ export class StandaloneStrategy extends AbstractStrategy {
8686
count: number,
8787
type?: RedisDataType,
8888
): Promise<void> {
89+
const COUNT = Math.min(2000, count);
90+
8991
let fullScanned = false;
9092
// todo: remove settings from here. threshold should be part of query?
9193
const settings = await this.settingsService.getAppSettings('1');
@@ -97,7 +99,7 @@ export class StandaloneStrategy extends AbstractStrategy {
9799
node.scanned < settings.scanThreshold
98100
)
99101
) {
100-
let commandArgs = [`${node.cursor}`, 'MATCH', match, 'COUNT', count];
102+
let commandArgs = [`${node.cursor}`, 'MATCH', match, 'COUNT', COUNT];
101103
if (type) {
102104
commandArgs = [...commandArgs, 'TYPE', type];
103105
}
@@ -112,7 +114,7 @@ export class StandaloneStrategy extends AbstractStrategy {
112114
// eslint-disable-next-line no-param-reassign
113115
node.cursor = parseInt(nextCursor, 10);
114116
// eslint-disable-next-line no-param-reassign
115-
node.scanned += count;
117+
node.scanned += COUNT;
116118
node.keys.push(...keys);
117119
fullScanned = node.cursor === 0;
118120
}

0 commit comments

Comments
 (0)