/** * * @param array $results * @param GeocodeCached $locationInfo * @return int number of cached results */ private function cacheResult($results, $locationInfo, $date) { \SystemLogger::debug('Extracted results are being cached.'); $startTime = microtime(true); $showtimesHuge = []; $computeDistance = !$this->shouldDeferDistanceInfo(); foreach ($results as $theatreMovieShowtime) { $theatre = Theatre::getOrCreate($theatreMovieShowtime['theatre'], $locationInfo, $computeDistance, $computeDistance); if ($theatre) { foreach ($theatreMovieShowtime['movies'] as $movieShowtimeData) { $movie = Movie::getOrCreate($movieShowtimeData['movie']); if ($movie) { $showtimesHuge = array_merge($showtimesHuge, $this->setShowtimesData($theatre, $movie, $movieShowtimeData['showtimes'])); } } } else { \SystemLogger::warn("Could not create theatre with data: ", $theatreMovieShowtime['theatre']); } } $result = !empty($showtimesHuge) ? Showtime::table()->insert($showtimesHuge, true, true) : 0; $locationInfo->setLastUpdated($date); \SystemLogger::debug('CACHING OF of results completed in: ', microtime(true) - $startTime, 'ms'); return $result; }