Project

General

Profile

Actions

Task #6124

closed

Task #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

Added by Redmine Admin about 10 hours ago. Updated about 9 hours ago.

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 from IIkoEmployeesDownloadCommand.downloadEmployees.
  • InitialStatsGatheringCommandcompaniesService.findAll(Pageable.from(0, 1000000)).
  • CompaniesGarbageCollectionCommandcompaniesService.findAll(Pageable.unpaged()), then tryToObsoleteCompany per company.
  • EmployeesCompaniesPartnersDistributionCommand.runOldemployeesService.findAll(Pageable.unpaged()) (dead path, but the same shape).

Proposed change

  • Batch slice persistence: collect the slices for a fetch and saveAll them in one statement instead of map { 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

Also available in: Atom PDF