ÀÁåºÀÁåº? Äë庀 * @return void */ public function process() { if ($this->is_active()) { return; } $this->clearTotalAndProcessed(); @ini_set('memory_limit', '-1'); $dateRange = [ 'from' => date('Y-m-d', 0), 'to' => date('Y-m-d', strtotime('yesterday')) ]; $visitorModel = new VisitorsModel(); $rawData = $visitorModel->countDailyVisitors([ 'date' => $dateRange, 'include_hits' => true, 'bypass_cache' => true ]); if (empty($rawData)) { $this->setInitiated(); return; } // Set date as object key for easy lookup $rawData = array_column($rawData, null, 'date'); // Set start date based on the first available record $dateRange['from'] = array_key_first($rawData); // Get all dates within the range $dates = DateRange::getDatesInRange($dateRange); $batchData = []; foreach ($dates as $date) { // Get the row data for the current date, or default to zeros $row = $rawData[$date] ?? (object) ['date' => $date, 'visitors' => 0, 'hits' => 0]; $batchData[] = [$row->date, $row->visitors, $row->hits]; } $this->setTotal($batchData); // Define the batch size $batchSize = 100; $batches = array_chunk($batchData, $batchSize); // Push each batch to the queue foreach ($batches as $batch) { $this->push_to_queue(['data' => $batch]); } $this->setInitiated(); $this->save()->dispatch(); } }