perf(mileage): stream workbook export rows
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import type { DailyMileageRow } from '../../api/types';
|
||||
import type { MileageExportInput } from './mileageExport';
|
||||
import type { MileageExportInput, MileageWorkbookRow } from './mileageExport';
|
||||
|
||||
function excelColumn(index: number) {
|
||||
let value = index;
|
||||
@@ -87,14 +86,14 @@ export async function createMileageWorkbook(input: MileageExportInput) {
|
||||
if (isDateHeader) cell.numFmt = 'm/d';
|
||||
});
|
||||
|
||||
const rowsByVin = new Map<string, Map<string, DailyMileageRow>>();
|
||||
const rowsByVin = new Map<string, Map<string, MileageWorkbookRow>>();
|
||||
for (const row of input.mileageRows) {
|
||||
if (!rowsByVin.has(row.vin)) rowsByVin.set(row.vin, new Map());
|
||||
rowsByVin.get(row.vin)!.set(row.date, row);
|
||||
}
|
||||
input.vehicles.forEach((vehicle, index) => {
|
||||
const rowNumber = firstDataRow + index;
|
||||
const mileageByDate = rowsByVin.get(vehicle.vin) ?? new Map<string, DailyMileageRow>();
|
||||
const mileageByDate = rowsByVin.get(vehicle.vin) ?? new Map<string, MileageWorkbookRow>();
|
||||
const dailyValues = input.dates.map((date) => mileageByDate.get(date)?.dailyMileageKm ?? null);
|
||||
const total = dailyValues.reduce<number>((sum, value) => sum + (value ?? 0), 0);
|
||||
const row = sheet.getRow(rowNumber);
|
||||
|
||||
Reference in New Issue
Block a user