예제 #1
0
 /**
  * Get the top wikis by weekly pageviews optionally filtering by vertical (hub) and/or language
  *
  * @param string $hub [OPTIONAL] The name of the vertical (e.g. Gaming, Entertainment,
  * Lifestyle, etc.) to use as a filter
  * @param string $lang [OPTIONAL] The language code (e.g. en, de, fr, es, it, etc.) to use as a filter
  *
  * @return array A collection of results with id, name, hub, language, topic and domain
  */
 public function getTop($lang = null, $hub = null)
 {
     $this->wf->profileIn(__METHOD__);
     $cacheKey = $this->wf->SharedMemcKey(__METHOD__, self::CACHE_VERSION, $lang, $hub);
     $results = $this->wg->Memc->get($cacheKey);
     if (!is_array($results)) {
         $results = array();
         $wikis = DataMartService::getTopWikisByPageviews(DataMartService::PERIOD_ID_WEEKLY, self::MAX_RESULTS, $lang, $hub, 1);
         foreach ($wikis as $wikiId => $wiki) {
             //fetching data from WikiFactory
             //the table is indexed and values cached separately
             //so making one query for all of them or a few small
             //separate ones doesn't make any big difference while
             //this respects WF's data abstraction layer
             //also: WF data is heavily cached
             $name = WikiFactory::getVarValueByName('wgSitename', $wikiId);
             $hubName = !empty($hub) ? $hub : $this->getVerticalByWikiId($wikiId);
             $langCode = WikiFactory::getVarValueByName('wgLanguageCode', $wikiId);
             $topic = WikiFactory::getVarValueByName('wgWikiTopics', $wikiId);
             $domain = $this->getDomainByWikiId($wikiId);
             $results[] = array('id' => $wikiId, 'name' => !empty($name) ? $name : null, 'hub' => $hubName, 'language' => !empty($langCode) ? $langCode : null, 'topic' => !empty($topic) ? $topic : null, 'domain' => $domain);
         }
         $this->wg->Memc->set($cacheKey, $results, 86400);
     }
     $this->wf->profileOut(__METHOD__);
     return $results;
 }
예제 #2
0
 public static function loadData($forceRefresh = false, $forceLanguage = null)
 {
     global $wgMemc, $wgStatsDB, $wgContLang, $wgExternalSharedDB, $wgStatsDBEnabled;
     wfProfileIn(__METHOD__);
     self::$mLanguage = !empty($forceLanguage) ? $forceLanguage : $wgContLang->getCode();
     $cacheKey = self::CACHE_KEY_TOKEN . ':' . strtoupper(self::$mLanguage);
     self::$mData = $wgMemc->get($cacheKey);
     if (empty(self::$mData) || $forceRefresh) {
         self::$mData = array();
         $wikisIDs = array();
         // get all the active wikis selected by the sales team
         $wikiFactoryRecommended = WikiFactory::getVarByName(self::WF_VAR_NAME, null);
         self::$mData['recommended'] = array();
         if (!empty($wikiFactoryRecommended) && !empty($wikiFactoryRecommended->cv_variable_id)) {
             $dbr = WikiFactory::db(DB_SLAVE);
             $res = $dbr->select(array('city_list', 'city_variables'), 'city_id', array('city_id = cv_city_id', 'city_public' => 1, 'city_lang' => self::$mLanguage, 'cv_variable_id' => $wikiFactoryRecommended->cv_variable_id, 'cv_value' => serialize(true)));
             while ($row = $dbr->fetchObject($res)) {
                 self::$mData['recommended'][] = $row->city_id;
             }
             $dbr->freeResult($res);
         }
         $counter = 0;
         self::$mData['hubs'] = array();
         if (!empty($wgStatsDBEnabled)) {
             $langs = array(self::$mLanguage);
             $wikis = DataMartService::getTopWikisByPageviews(DataMartService::PERIOD_ID_MONTHLY, 200, $langs, null, 1);
             $minPageViews = isset(self::$pageviewsLimits[self::$mLanguage]) ? self::$pageviewsLimits[self::$mLanguage] : self::$pageviewsLimits['default'];
             foreach ($wikis as $wikiID => $pvCount) {
                 if ($pvCount >= $minPageViews) {
                     $hub = WikiFactoryHub::getInstance();
                     $cat_id = $hub->getCategoryId($wikiID);
                     if (!$cat_id) {
                         continue;
                     }
                     if (!isset(self::$mData['hubs'][$cat_id])) {
                         self::$mData['hubs'][$cat_id] = array();
                     }
                     self::$mData['hubs'][$cat_id][] = $wikiID;
                     $counter++;
                 }
             }
         }
         // removing entries from hubs that have a match in recommended
         if (!empty(self::$mData['recommended']) && !empty(self::$mData['hubs'])) {
             $counter = 0;
             foreach (self::$mData['hubs'] as $hubID => &$item) {
                 $item = array_diff($item, self::$mData['recommended']);
                 $counter += count($item);
             }
         }
         self::$mData['total'] = $counter;
         $wgMemc->set($cacheKey, self::$mData, 3600 * self::CACHE_EXPIRY);
     }
     wfProfileOut(__METHOD__);
 }
예제 #3
0
 /**
  * get popular wikis
  * @param integer $wikiId
  * @param integer $limit (number of users)
  * @return array $popularWikis
  */
 protected function getPopularWikis($limit = 50)
 {
     $this->wf->ProfileIn(__METHOD__);
     $memKey = $this->wf->SharedMemcKey('userlogin', 'popular_wikis');
     $popularWikis = $this->wg->Memc->get($memKey);
     if (empty($popularWikis)) {
         $popularWikis = array_keys(DataMartService::getTopWikisByPageviews(DataMartService::PERIOD_ID_MONTHLY, $limit));
         if (empty($popularWikis)) {
             $popularWikis[] = self::WIKIA_CITYID_COMMUNITY;
         }
         $this->wg->Memc->set($memKey, $popularWikis, 60 * 60 * 24);
     }
     $this->wf->ProfileOut(__METHOD__);
     return $popularWikis;
 }
 protected function getTopWikis()
 {
     wfProfileIn(__METHOD__);
     $key = wfMemcKey(__CLASS__, self::MEMC_VERSION, __METHOD__);
     $data = $this->wg->memc->get($key, null);
     if (!empty($data)) {
         wfProfileOut(__METHOD__);
         return $data;
     }
     $ids = DataMartService::getTopWikisByPageviews(DataMartService::PERIOD_ID_MONTHLY, 200);
     $this->wg->memc->set($key, $ids, 86400);
     wfProfileOut(__METHOD__);
     return $ids;
 }
 /**
  * Checks if a given wikia is in the top 200 in terms of pageviews
  * @param  int     $city_id
  * @return boolean
  */
 public function isTop200($city_id)
 {
     wfProfileIn(__METHOD__);
     $sCacheKey = wfSharedMemcKey(__CLASS__, __METHOD__);
     // Check in memcache before using DataMartService
     if (!is_null($this->app->wg->Memc->get($sCacheKey))) {
         $aTop200Wikis = $this->app->wg->Memc->get($sCacheKey);
     } else {
         $aTop200Wikis = DataMartService::getTopWikisByPageviews(DataMartService::PERIOD_ID_MONTHLY);
         $this->app->wg->Memc->set($sCacheKey, $aTop200Wikis, \WikiaResponse::CACHE_LONG);
     }
     // city_ids are keys; return true if that one is set.
     if (isset($aTop200Wikis[$city_id])) {
         wfProfileOut(__METHOD__);
         return true;
     }
     wfProfileOut(__METHOD__);
     return false;
 }