protected function getPageViews($period) { $timestamp = strtotime($period); $startDate = date('Y-m-d', $timestamp); $endDate = date('Y-m-d', strtotime('-1 day')); $res = 0; $pageviews = DataMartService::getPageviewsMonthly($startDate, $endDate, $this->id); if (!empty($pageviews) && is_array($pageviews)) { foreach ($pageviews as $date => $value) { $res += $value; } } return intval($res); }
/** * Provided an Article, queries the database for weekly and monthly pageviews. * @return array */ public function execute() { wfProfileIn(__METHOD__); $service = $this->getService(); if ($this->result !== null || !$service->isOnDbCluster()) { wfProfileOut(__METHOD__); return $this->result; } $stringKey = 'WikiaSearchPageViews'; $result = $this->service->getCacheResultFromString($stringKey); if ($result !== false && ($result->weekly > 0 || $result->monthly > 0)) { wfProfileOut(__METHOD__); $this->result = array('wikiviews_weekly' => (int) $result->weekly, 'wikiviews_monthly' => (int) $result->monthly); return $this->result; } $row = new \stdClass(); $row->weekly = 0; $row->monthly = 0; $datamart = new \DataMartService(); $startDate = date('Y-m-d', strtotime('-1 week')); $endDate = date('Y-m-01', strtotime('now')); $pageviews_weekly = $datamart->getPageviewsWeekly($startDate, $endDate, $this->service->getWikiId()); if (!empty($pageviews_weekly)) { foreach ($pageviews_weekly as $pview) { $row->weekly += $pview; } } $startDate = date('Y-m-01', strtotime('-1 month')); $pageviews_monthly = $datamart->getPageviewsMonthly($startDate, $endDate, $this->service->getWikiId()); if (!empty($pageviews_monthly)) { foreach ($pageviews_monthly as $pview) { $row->monthly += $pview; } } $wrapper = new \Wikia\Util\GlobalStateWrapper(array('wgAllowMemcacheWrites' => true)); $wrapper->wrap(function () use($stringKey, $row) { $this->service->setCacheFromStringKey($stringKey, $row, self::WIKIPAGES_CACHE_TTL); }); $this->result = array('wikiviews_weekly' => (int) $row->weekly, 'wikiviews_monthly' => (int) $row->monthly); wfProfileOut(__METHOD__); return $this->result; }
private function getWikisByNbrPageviews() { global $wgMemc, $wgStatsDB, $wgStatsDBEnabled; $pageViews = $this->axNbrPageviews; $pageViewsDays = $this->axNbrPageviewsDays; if (empty($pageViewsDays)) { $pageViewsDays = self::DEF_DAYS_PVIEWS; } $memkey = __METHOD__ . "v:" . $pageViews . "vd:" . $pageViewsDays . "vc:" . md5(implode(",", $this->cityIds)); $cities = $wgMemc->get($memkey); if (empty($cities) && !empty($wgStatsDBEnabled)) { $startDate = date('Y-m-01', strtotime('-3 month')); $endDate = date('Y-m-01', strtotime('now')); $pageviews = DataMartService::getPageviewsMonthly($startDate, $endDate, $this->cityIds); if (empty($pageviews)) { foreach ($pageviews as $wiki_id => $wiki_data) { #--- if ($wiki_data['SUM'] > intval($pageViews)) { continue; } $this->mPageViews[$wiki_id] = $wiki_data['SUM']; $cities[] = $wiki_id; } } $wgMemc->set($memkey, $cities, 3600); } return $cities; }