*/ protected $returnType = AnalyticsPodcastsBySubscription::class; /** * @var bool */ protected $useSoftDeletes = false; /** * @var bool */ protected $useTimestamps = false; public function getNumberOfDownloadsLast3Months(int $podcastId, int $subscriptionId): int { $cacheName = "{$podcastId}_{$subscriptionId}_analytics_podcast_by_subscription"; if ( ! ($found = cache($cacheName)) ) { $found = (int) ($this->builder() ->selectSum('hits', 'total_hits') ->where([ 'podcast_id' => $podcastId, 'subscription_id' => $subscriptionId, ]) ->where('`date` >= UTC_TIMESTAMP() - INTERVAL 3 month', null, false) ->get() ->getResultArray())[0]['total_hits']; cache() ->save($cacheName, $found, 600); } return $found; } }