From ff476ad40697ce532295ad7a5bd90829db5242b6 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Fri, 25 Oct 2024 21:06:45 -0500 Subject: [PATCH] fix:speed up daily change sync --- app/Models/Portfolio.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Models/Portfolio.php b/app/Models/Portfolio.php index 6c2285e..dec7543 100644 --- a/app/Models/Portfolio.php +++ b/app/Models/Portfolio.php @@ -190,9 +190,18 @@ class Portfolio extends Model if (!empty($total_performance)) { DB::transaction(function () use ($total_performance) { - $this->daily_change()->delete(); - - DailyChange::insert($total_performance); + + $this->daily_change()->upsert( + $total_performance, + ['date', 'portfolio_id'], + [ + 'total_market_value', + 'total_cost_basis', + 'total_gain', + 'realized_gains', + 'total_dividends_earned' + ] + ); }); } }