fix: data integrity - dedup prices, batch writes, safe parsePrice, remove hardcoded locality #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/data-integrity"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
prices(station_id, fuel_type, fecha_actualizacion)to prevent unbounded growth from duplicate price entries on every scheduler run. UsesINSERT OR IGNOREto skip gracefully.savePricesBatch()wraps all station+price saves in a single SQLite transaction instead of 40-60 individual transactions per collection cycle.parsePrice()returnsnullfor invalid data instead of0, which would have been stored as a real price and displayed to users as "0.000 EUR/L". Stations with unparseable prices are now filtered out.filterByPostalCodePrefix()no longer silently ORs in stations wherelocalidad.startsWith('lorca'), which bypassed postal code filtering and was coupled to a specific city.Files changed
src/lib/db.ts— Unique index,INSERT OR IGNORE, newsavePricesBatch()with transactionsrc/lib/api.ts—parsePrice()returnsnull,parseStationData()filters nulls, locality check removedsrc/lib/scheduler.ts— UsessavePricesBatch()instead of loop with individual savesTest plan
bun test— all 30 tests pass2c4ac06a13to5ecdd0f205