From 0c29393f3b2e7610d57910abf775b0bc12cc2881 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Thu, 7 Nov 2024 20:40:55 -0600 Subject: [PATCH] fix: skip dividend sync if most recent dividend was less than 24 hours ago --- app/Models/Dividend.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Models/Dividend.php b/app/Models/Dividend.php index b6fe241..ebf6d40 100644 --- a/app/Models/Dividend.php +++ b/app/Models/Dividend.php @@ -50,10 +50,8 @@ class Dividend extends Model /** * Grab new dividend data * - * @param string $symbol - * @return void */ - public static function refreshDividendData(string $symbol) + public static function refreshDividendData(string $symbol): void { $dividends_meta = self::where(['symbol' => $symbol]) ->selectRaw('COUNT(symbol) as total_dividends') @@ -68,7 +66,13 @@ class Dividend extends Model // nope, refresh forward looking only if ( $dividends_meta->total_dividends ) { - $start_date = $dividends_meta->last_date->addHours(48); + $start_date = $dividends_meta->last_date->addHours(24); + } + + // skip refresh if there's already recent data + if ($start_date >= $end_date) { + + return; } // get some data @@ -99,8 +103,6 @@ class Dividend extends Model $market_data->last_dividend_amount = $dividend_data->sortByDesc('date')->first()['dividend_amount']; $market_data->save(); } - - return $dividend_data; } public static function syncHoldings(string $symbol): void