Actions
Task #6124
closedTask #6116: EPIC: Speed up the stats updater daemon (scripts/workflow/update_stats.sh)
Replace per-row DB writes and unpaged full-table loads in the sync commands
Status:
Resolved
Priority:
Normal
Assignee:
-
Start date:
08/26/2026
Due date:
% Done:
100%
Estimated time:
Description
Problem¶
Several hot loops do one DB round-trip per row, or load an entire table into memory:
-
IikoStatsGatheringService:151/IikoOlapV2MetricFetchingService.fetchReport(...).map { statSlicesService.save(it) }— one INSERT per stat slice. -
EmployeesFromIikoServerDtoComposingService.compose— two SELECTs (companiesService.findByCode,employeesService.findByIikoId) for every employee, on every round, called fromIIkoEmployeesDownloadCommand.downloadEmployees. -
InitialStatsGatheringCommand—companiesService.findAll(Pageable.from(0, 1000000)). -
CompaniesGarbageCollectionCommand—companiesService.findAll(Pageable.unpaged()), thentryToObsoleteCompanyper company. -
EmployeesCompaniesPartnersDistributionCommand.runOld—employeesService.findAll(Pageable.unpaged())(dead path, but the same shape).
Proposed change¶
- Batch slice persistence: collect the slices for a fetch and
saveAllthem in one statement instead ofmap { save(it) }. - In the employee import, preload companies by code and employees by iiko id into maps once, then resolve in memory; batch the inserts and updates.
- Replace the unpaged/1,000,000 loads with paged iteration.
Acceptance¶
- Employee import issues O(1) lookup queries instead of O(n).
- Stat slices are persisted in batches.
- No
Pageable.unpaged()/Pageable.from(0, 1000000)left in the daemon's commands.
Actions