Skip to content

Commit e66ca7c

Browse files
Merge pull request #2422 from RedisInsight/be/feature/RI-4650_trim_bulk_import
Be/feature/ri 4650 trim bulk import
2 parents 8806664 + d179c67 commit e66ca7c

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

redisinsight/api/src/modules/bulk-actions/bulk-import.service.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ describe('BulkImportService', () => {
232232
expect(mockIORedisClient.disconnect).toHaveBeenCalled();
233233
});
234234

235+
it('should ignore blank lines', async () => {
236+
await service.import(mockClientMetadata, {
237+
file: {
238+
...mockUploadImportFileDto.file,
239+
buffer: Buffer.from('\n SET foo bar \n \n SET foo bar \n '),
240+
} as unknown as MemoryStoredFile,
241+
})
242+
expect(spy).toBeCalledWith(mockIORedisClient, [['set', ['foo', 'bar']], ['set', ['foo', 'bar']]])
243+
expect(mockIORedisClient.disconnect).toHaveBeenCalled();
244+
});
245+
235246
it('should throw an error in case of global error', async () => {
236247
try {
237248
databaseConnectionService.createClient.mockRejectedValueOnce(new NotFoundException());

redisinsight/api/src/modules/bulk-actions/bulk-import.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ export class BulkImportService {
101101
const rl = readline.createInterface(stream);
102102
rl.on('line', (line) => {
103103
try {
104-
const [command, ...args] = splitCliCommandLine((line));
104+
const [command, ...args] = splitCliCommandLine((line.trim()));
105105
if (batch.length >= BATCH_LIMIT) {
106106
batchResults.push(this.executeBatch(client, batch));
107107
batch = [];
108108
}
109-
110-
batch.push([command.toLowerCase(), args]);
109+
if (command) {
110+
batch.push([command.toLowerCase(), args]);
111+
}
111112
} catch (e) {
112113
parseErrors += 1;
113114
}

redisinsight/api/test/api/bulk-actions/POST-databases-id-bulk_actions-import.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,40 @@ describe('POST /databases/:id/bulk-actions/import', () => {
138138
},
139139
});
140140
});
141+
it('Should ignore blank lines', async () => {
142+
await validateApiCall({
143+
endpoint,
144+
attach: [
145+
'file',
146+
Buffer.from(`
147+
\n
148+
\n
149+
SET key0 value0
150+
\n
151+
\n
152+
SET key1 value1
153+
\n
154+
\n
155+
`),
156+
'any_filename_and_ext',
157+
],
158+
responseBody: {
159+
id: 'empty',
160+
databaseId: constants.TEST_INSTANCE_ID,
161+
type: 'upload',
162+
summary: { processed: 2, succeed: 2, failed: 0, errors: [] },
163+
progress: null,
164+
filter: null,
165+
status: 'completed',
166+
},
167+
checkFn: async ({ body }) => {
168+
expect(body.duration).to.gt(0);
169+
170+
expect(await rte.client.get('key0')).to.eq('value0');
171+
expect(await rte.client.get('key1')).to.eq('value1');
172+
},
173+
});
174+
});
141175
it('Should import 100K strings', async () => {
142176
const b = Buffer.from(
143177
(new Array(100_000)).fill(1).map(

0 commit comments

Comments
 (0)