Fixing the error when importing a large Excel file

This commit is contained in:
2026-10-03 15:01:01 +03:30
parent f8313c0ea5
commit 2e315c9cfd
15 changed files with 503 additions and 86 deletions
@@ -10,6 +10,10 @@ import {
writeXlsx,
type ExcelPreviewResult,
} from '../common/excel';
import {
chunkImportMeta,
resolveExcelImportChunk,
} from '../common/excel-import-session';
import { ProductsService } from './products.service';
const PRODUCT_COLUMNS = [
@@ -116,15 +120,24 @@ export class ProductsExcelService {
async import(
organizationId: string,
file: Express.Multer.File,
file: Express.Multer.File | undefined,
mappingRaw?: string,
chunk?: { sessionId?: string; offset?: string | number; limit?: string | number },
): Promise<ImportContactsResult> {
const rows = await readMappedRows(file, PRODUCT_ALIASES, parseExcelMapping(mappingRaw));
const ctx = await resolveExcelImportChunk({
organizationId,
file,
sessionId: chunk?.sessionId,
offset: chunk?.offset,
limit: chunk?.limit,
loadRows: () =>
readMappedRows(file!, PRODUCT_ALIASES, parseExcelMapping(mappingRaw)),
});
const result: ImportContactsResult = { created: 0, skipped: 0, errors: [] };
for (let i = 0; i < rows.length; i++) {
const row = rows[i]!;
const rowNum = i + 2;
for (let i = 0; i < ctx.slice.length; i++) {
const row = ctx.slice[i]!;
const rowNum = ctx.offset + i + 2;
if ((row._type || '').trim() && row._type.trim().toLowerCase() !== 'product') {
continue;
}
@@ -176,6 +189,6 @@ export class ProductsExcelService {
}
}
return result;
return { ...result, ...chunkImportMeta(ctx) };
}
}
+9 -2
View File
@@ -84,10 +84,17 @@ export class ProductsController {
)
import(
@CurrentUser() user: Actor,
@UploadedFile() file: Express.Multer.File,
@UploadedFile() file: Express.Multer.File | undefined,
@Body('mapping') mapping?: string,
@Body('sessionId') sessionId?: string,
@Body('offset') offset?: string,
@Body('limit') limit?: string,
) {
return this.excelService.import(user.organizationId, file, mapping);
return this.excelService.import(user.organizationId, file, mapping, {
sessionId,
offset,
limit,
});
}
@Get(':id')