sync: clean stale local pricelists and migrate runtime config handling

This commit is contained in:
2026-02-08 10:01:27 +03:00
parent eb8555c11a
commit 593280de99
12 changed files with 434 additions and 426 deletions

View File

@@ -340,6 +340,10 @@ func (s *Service) SyncPricelists() (int, error) {
if err != nil {
return 0, fmt.Errorf("getting active server pricelists: %w", err)
}
serverPricelistIDs := make([]uint, 0, len(serverPricelists))
for i := range serverPricelists {
serverPricelistIDs = append(serverPricelistIDs, serverPricelists[i].ID)
}
synced := 0
var latestEstimateLocalID uint
@@ -388,6 +392,13 @@ func (s *Service) SyncPricelists() (int, error) {
synced++
}
removed, err := s.localDB.DeleteUnusedLocalPricelistsMissingOnServer(serverPricelistIDs)
if err != nil {
slog.Warn("failed to cleanup stale local pricelists", "error", err)
} else if removed > 0 {
slog.Info("deleted stale local pricelists", "deleted", removed)
}
// Update component prices from latest estimate pricelist only.
if latestEstimateLocalID > 0 {
updated, err := s.localDB.UpdateComponentPricesFromPricelist(latestEstimateLocalID)