1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Batch upsert security prices on sync

This commit is contained in:
Zach Gollwitzer 2025-05-09 15:56:48 -04:00
parent ab2cec55e7
commit 7605b0221d

View file

@ -63,7 +63,21 @@ module Security::Provided
is_invalid
end
Security::Price.upsert_all(valid_prices, unique_by: %i[security_id date currency])
valid_prices.each_slice(100) do |batch|
retries ||= 0
begin
Security::Price.upsert_all(batch, unique_by: %i[security_id date currency])
rescue => e
if retries < 3
retries += 1
sleep(1)
retry
else
raise e
end
end
end
end
def find_or_fetch_price(date: Date.current, cache: true)