mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 22:28:51 +01:00
Cache space follower + User follow without notifications.
This commit is contained in:
parent
ee66981407
commit
5f1fd3ff22
@ -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) {
|
||||
|
@ -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';
|
||||
|
Loading…
x
Reference in New Issue
Block a user