public function actionAll() { $startAll = microtime(true); $discusComponent = Yii::app()->disqusComments; /** @var EDisqusComments $discusComponent */ $commentsPages = DisqusComments::model()->findAll(); foreach ($commentsPages as $commentsPage) { $start = microtime(true); $commentsPage->setScenario('syncComments'); $commentsFromApi = $discusComponent->loadCommentsByUrl($commentsPage->page_url); if (is_array($commentsFromApi) && !empty($commentsFromApi)) { $comments = EDisqusComments::formatComments($commentsFromApi); $commentsHierarchy = EDisqusComments::sortCommentsByHierarchy($comments); $commentsPage->comments_block = json_encode($commentsHierarchy); $commentsPage->update_time = time(); $commentsPage->save(); } echo 'generated for ' . $commentsPage->page_url . ' in '; echo microtime(true) - $start . " seconds. \n"; } $finishAll = microtime(true); \Yii::app()->setGlobalState('DisqusComments', $finishAll); echo 'generated ALL in '; echo $finishAll - $startAll . " seconds. \n"; }
public function run() { if (Yii::app()->request->isAjaxRequest) { if (isset($_POST['page_url'])) { $url = $_POST['page_url']; $disqusComponent = Yii::app()->disqusComments; /** @var EDisqusComments $disqusComponent */ $duration = $disqusComponent->queryCacheDuration; $dependency = new \CGlobalStateCacheDependency('DisqusComments'); $comments = DisqusComments::model()->cache($duration, $dependency)->findByAttributes(array('page_url' => $url)); if (!isset($comments)) { DisqusComments::saveNewUrl($url); } echo EDisqusComments::createCommentsJSON($comments->comments_block); } } }
public function run() { $disqusComponent = Yii::app()->disqusComments; /** @var EDisqusComments $disqusComponent */ $commentsBlock = $disqusComponent->getCache('commentBlock_' . md5($this->pageUrl)); if ($commentsBlock === false) { $duration = $disqusComponent->queryCacheDuration; $dependency = new \CGlobalStateCacheDependency('DisqusComments'); $disqusComments = DisqusComments::model()->cache($duration, $dependency)->findByAttributes(array('page_url' => $this->pageUrl)); if (isset($disqusComments)) { $comments = json_decode($disqusComments->comments_block); $commentsBlock = EDisqusComments::createCommentsHTML($comments); } else { $commentsBlock = ''; if ($disqusComponent->autoUpdateMap && !empty($this->pageUrl)) { DisqusComments::saveNewUrl($this->pageUrl); } } $disqusComponent->setCache('commentBlock_' . md5($this->pageUrl), $commentsBlock); } $this->render('disqusCommentsWidget', array('commentsBlock' => $commentsBlock, 'apiKey' => $disqusComponent->apiKey, 'shortName' => $disqusComponent->shortName)); }