$updates =
[];
foreach ($products as $product) { $newStates =
$this->
getNewStates($product);
$oldStates =
$product['states'
] ?
json_decode((string) $product['states'
], true, 512, \JSON_THROW_ON_ERROR
) :
[];
if (\
count(array_diff($newStates,
$oldStates)) === 0
) { continue;
} $updates[] =
new UpdatedStates($product['id'
],
$oldStates,
$newStates);
} if (empty($updates)) { return;
} $query =
new RetryableQuery( $this->connection,
$this->connection->
prepare('UPDATE `product` SET `states` = :states WHERE `id` = :id AND `version_id` = :version'
) );