/** * Fetches the data from the persistent data storage. * @throws Exception * @return array list of data items */ protected function fetchData() { foreach ($this->queryOptions as $name => $value) { $this->query->option($name, $value); } if (($pagination = $this->getPagination('Pagination')) !== false) { $pagination->setItemCount($this->getTotalItemCount()); $this->query->limit($pagination->getLimit())->offset($pagination->getOffset()); } if (($sort = $this->getSort()) !== false && ($order = $sort->getOrderBy()) != '') { foreach (explode(',', $order) as $orderAttribute) { $orderAttribute = trim($orderAttribute); $field = trim(preg_replace('#(desc|asc)$#sui', '', $orderAttribute)); if (preg_match('#(desc|asc)$#sui', $orderAttribute, $matches)) { $direction = $matches[1] === 'desc' ? true : false; } else { $direction = $sort->getDirection($field); } $this->query->order($field, $direction ? 'DESC' : 'ASC'); } } $sql = $this->query->build(); $data = array(); try { $data = Yii::app()->sphinx->cache($this->cacheTime)->createCommand($sql)->queryAll(); } catch (Exception $e) { Yii::log('LSphinxDataProvider exception' . PHP_EOL . 'Message: ' . $e->getMessage() . 'Trace: ' . $e->getTraceAsString(), CLogger::LEVEL_ERROR); if (YII_DEBUG) { throw $e; } } return $data; }
public static function getLastTorrentIdsByCategories($count = 5, $forceRefresh = false) { $key = 'tags_last_torrents_ids'; $torrentsIds = Yii::app()->cache->get($key); try { if (empty($torrentsIds) || $forceRefresh) { $torrentsIds = array(); $tags = LCategory::$categoriesTags; foreach ($tags as $tag) { $obj = new ESphinxQL(); $obj->addField('id')->addIndex(Yii::app()->params['sphinx']['indexes']['torrents'])->option('ranker', 'SPH04')->search('@tags "' . $obj->halfEscapeMatch($tag) . '"')->where('torrent_status', LTorrent::TORRENT_STATUS_GOOD)->order('weight()', 'DESC')->order('id', 'DESC')->limit($count); $torrentsIds = array_merge($torrentsIds, Yii::app()->sphinx->cache(600)->createCommand($obj->build())->queryColumn()); } Yii::app()->cache->set($key, $torrentsIds); } } catch (Exception $e) { Yii::log('getLastTorrentIdsByCategories failed. Exception: ' . $e->getMessage() . PHP_EOL . 'Trace: ' . $e->getTrace(), CLogger::LEVEL_ERROR); if (YII_DEBUG) { throw $e; } } return $torrentsIds; }