Upsert and API optimization