Cache space follower + User follow without notifications.

This commit is contained in:
buddh4 2017-02-01 14:49:06 +01:00
parent ee66981407
commit 5f1fd3ff22
2 changed files with 13 additions and 4 deletions

View File

@ -34,6 +34,8 @@ use humhub\modules\user\models\User;
*/
class Followable extends Behavior
{
private $_followerCache = [];
public function beforeDelete($event)
{
@ -117,9 +119,11 @@ class Followable extends Behavior
/**
* Checks if the given user follows this owner record.
*
* Note that the followers for this owner will be cached.
*
* @param int $userId
* @param boolean $withNotifcations if true, only return true when also notifications enabled
* @param boolean $withNotifications if true, only return true when also notifications enabled
* @return boolean Is object followed by user
*/
public function isFollowedByUser($userId = null, $withNotifications = false)
@ -130,8 +134,13 @@ class Followable extends Behavior
$userId = \Yii::$app->user->id;
}
$record = $this->getFollowRecord($userId);
if ($record !== null) {
if(!isset($this->_followerCache[$userId])) {
$this->_followerCache[$userId] = $this->getFollowRecord($userId);
}
$record = $this->_followerCache[$userId];
if ($record) {
if ($withNotifications && $record->send_notifications == 1) {
return true;
} elseif (!$withNotifications) {

View File

@ -84,7 +84,7 @@ class ProfileController extends ContentContainerController
public function actionFollow()
{
$this->forcePostRequest();
$this->getUser()->follow();
$this->getUser()->follow(Yii::$app->user->getIdentity(), false);
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';