sync: clean stale local pricelists and migrate runtime config handling
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user