Skip to content

Commit

Permalink
aggregate_rating cache improve #1
Browse files Browse the repository at this point in the history
  • Loading branch information
chiliec committed Jan 25, 2015
1 parent db34b75 commit f787cf9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions actions/VoteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function run()
$newVote->user_id = (string)$user_id;
$newVote->value = $act;
if($newVote->save()) {
Yii::$app->cache->delete('aggregate_rating'.$model_name.$target_id);
if($act===1) {
Yii::$app->cache->delete('likes'.$model_name.$target_id);
return ['content' => Yii::t('vote', 'Your vote is accepted. Thanks!'), 'successfully' => true];
Expand Down
2 changes: 1 addition & 1 deletion models/Rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getRating($model_name, $target_id)
$rating = 0;
}
$rating = round($rating*10, 2);
Yii::$app->cache->set('aggregate_rating'.$model_name.$target_id, $rating, 60*60); // кешируем на час
Yii::$app->cache->set('aggregate_rating'.$model_name.$target_id, $rating);
}

return ['likes'=>$likes, 'dislikes'=>$dislikes, 'aggregate_rating'=>$rating];
Expand Down

0 comments on commit f787cf9

Please sign in to comment.