Skip to content

Issue-229: cleared User cache #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion class.groups.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public function categoryModel_setCategoryMetaData_create(CategoryModel $sender)
$userMetaModel->setUserMeta($userID, $newPopupCommentKey , $watched);
$userMetaModel->setUserMeta($userID, $newPopupDiscussionKey , $watched);
}
return $sender->hasWatched($categoryIDs,$userID);
return;// $sender->hasWatched($categoryIDs,$userID);
}

/**
Expand Down
82 changes: 50 additions & 32 deletions models/class.groupmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,17 +830,19 @@ public function checkPermission($userID,$groupID,$categoryID = null, $permission
* @return bool|Gdn_DataSet|object|string
*/
public function join($GroupID, $UserID, $watched = true, $followed = true ){
$results = [];
$Fields = ['Role' => GroupModel::ROLE_MEMBER, 'GroupID' => $GroupID,'UserID' => $UserID, 'DateInserted' => Gdn_Format::toDateTime()];
if( $this->SQL->getWhere('UserGroup', ['GroupID' => $GroupID,'UserID' => $UserID])->numRows() == 0) {
$this->SQL->insert('UserGroup', $Fields);
if($followed) {
$this->followGroup($GroupID, $UserID);
if($followed === true) {
$results['Followed'] = $this->followGroup($GroupID, $UserID);
}
if($watched) {
$this->watchGroup($GroupID, $UserID);
if($watched === true) {
$results['Watched'] = $this->watchGroup($GroupID, $UserID);
}
$this->notifyJoinGroup($GroupID, $UserID);
}
return $results;
}

/**
Expand Down Expand Up @@ -1249,24 +1251,31 @@ public function hasWatchedGroup($group) {
*
*/
public function followGroup($group, $userID) {
$result = [];
if(is_numeric($group) && $group > 0) {
$group = $this->getByGroupID($group);
}

if($group->ChallengeID) {
$categoryModel = new CategoryModel();
// Remove existing UserCategory cache
// Before calculating the user-specific information on a category.
CategoryModel::clearUserCache($userID);
Gdn::cache()->remove("Follow_{$userID}");
$categoryModel = CategoryModel::instance();
$groupCategory = $categoryModel->getByCode($group->ChallengeID);
if($groupCategory->DisplayAs !== 'Discussions') {
$categories = CategoryModel::getSubtree($groupCategory->CategoryID, false);
$categoryIDs = array_column($categories, 'CategoryID');
} else {
$categoryIDs = [$groupCategory->CategoryID];
}

$parentCategoryID = val('CategoryID', $groupCategory);
$isFollowed = $categoryModel->follow($userID, $parentCategoryID, true);
$result[strval($parentCategoryID)] = $isFollowed;
$childrenCategories = CategoryModel::getChildren($parentCategoryID);
$categoryIDs = array_column($childrenCategories, 'CategoryID');
foreach($categoryIDs as $categoryID) {
$categoryModel->follow($userID, $categoryID, true);
$isFollowed = $categoryModel->follow($userID, $categoryID, true);
$result[strval($categoryID)] = $isFollowed;
}

CategoryModel::clearUserCache($userID);
}
return $result;
}

/**
Expand All @@ -1281,16 +1290,14 @@ public function unfollowGroup($group, $userID) {
if($group->ChallengeID) {
$categoryModel = new CategoryModel();
$groupCategory = $categoryModel->getByCode($group->ChallengeID);
if($groupCategory->DisplayAs !== 'Discussions') {
$categories = CategoryModel::getSubtree($groupCategory->CategoryID, false);
$categoryIDs = array_column($categories, 'CategoryID');
} else {
$categoryIDs = [$groupCategory->CategoryID];
}
$categories = CategoryModel::getSubtree($groupCategory->CategoryID, true);
$categoryIDs = array_column($categories, 'CategoryID');

foreach($categoryIDs as $categoryID) {
$categoryModel->follow($userID, $categoryID, false);
}

CategoryModel::clearUserCache($userID);
}
}

Expand All @@ -1299,21 +1306,30 @@ public function unfollowGroup($group, $userID) {
* @param $group
*/
public function watchGroup($group, $userID) {
$results = [];
if(is_numeric($group) && $group > 0) {
$group = $this->getByGroupID($group);
}

if($group->ChallengeID) {
$categoryModel = new CategoryModel();
// Remove existing UserCategory cache
// Before calculating the user-specific information on a category.
CategoryModel::clearUserCache($userID);
Gdn::cache()->remove("UserMeta_{$userID}");

$categoryModel = CategoryModel::instance();
$groupCategory = $categoryModel->getByCode($group->ChallengeID);
if($groupCategory->DisplayAs !== 'Discussions') {
$categories = CategoryModel::getSubtree($groupCategory->CategoryID, true);
$categoryIDs = array_column($categories, 'CategoryID');
} else {
$categoryIDs = [$groupCategory->CategoryID];
}
$parentCategoryID = val('CategoryID', $groupCategory);
$childrenCategories = CategoryModel::getChildren($parentCategoryID);
$categoryIDs = array_column($childrenCategories, 'CategoryID');
array_push($categoryIDs, $parentCategoryID);
$categoryModel->setCategoryMetaData($categoryIDs, $userID, 1);
$userMetaModel = new UserMetaModel();
$results = $userMetaModel->getUserMeta($userID);
CategoryModel::clearUserCache($userID);
}

return $results;
}

/**
Expand All @@ -1326,15 +1342,17 @@ public function unwatchGroup($group, $userID) {
}

if($group->ChallengeID) {
CategoryModel::clearUserCache($userID);
Gdn::cache()->remove("UserMeta_{$userID}");
$categoryModel = new CategoryModel();
$groupCategory = $categoryModel->getByCode($group->ChallengeID);
if($groupCategory->DisplayAs !== 'Discussions') {
$categories = CategoryModel::getSubtree($groupCategory->CategoryID, true);
$categoryIDs = array_column($categories, 'CategoryID');
} else {
$categoryIDs = [$groupCategory->CategoryID];
}
$parentCategoryID = val('CategoryID', $groupCategory);
$childrenCategories = CategoryModel::getChildren($parentCategoryID);
$categoryIDs = array_column($childrenCategories, 'CategoryID');
array_push($categoryIDs, $parentCategoryID);
$categoryModel->setCategoryMetaData($categoryIDs, $userID, null);

CategoryModel::clearUserCache($userID);
}
}

Expand Down