Skip to content
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

Issue #3445902: Apply static caching to the SocialPrivateMessageService #3893

Merged
merged 1 commit into from
May 21, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,46 @@ public function deleteUserDataThreadInfo(EntityBase $entity) {
* The number of unread threads.
*/
public function updateUnreadCount() {
$unread = 0;
$unread = &drupal_static(__FUNCTION__);

// Get the user.
$uid = $this->currentUser->id();
/** @var \Drupal\user\UserStorageInterface $user_storage */
$user_storage = $this->userManager;
/** @var \Drupal\user\UserInterface $user */
$user = $user_storage->load($uid);
if (!isset($unread)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only actual change together with line 66, the rest is indentation.

$unread = 0;

// Get all the thread id's for this user.
$threads = $this->mapper->getThreadIdsForUser($user);
// Get the user.
$uid = $this->currentUser->id();
/** @var \Drupal\user\UserStorageInterface $user_storage */
$user_storage = $this->userManager;
/** @var \Drupal\user\UserInterface $user */
$user = $user_storage->load($uid);

if (empty($threads)) {
return $unread;
}
// Get all the thread id's for this user.
$threads = $this->mapper->getThreadIdsForUser($user);

// Check the last time someone other than the current user added
// something to the threads.
$thread_last_messages = $this->getLastMessagesFromOtherUsers($uid, $threads);
if (empty($thread_last_messages)) {
return $unread;
}
if (empty($threads)) {
return $unread;
}

foreach ($thread_last_messages as $thread_id => $last_message) {
// Check if the user has a timestamp on the thread.
$thread_last_check = $this->userData->get('private_message', $uid, 'private_message_thread:' . $thread_id);
if ($thread_last_check === NULL) {
$thread_last_check = 0;
// Check the last time someone other than the current user added
// something to the threads.
$thread_last_messages = $this->getLastMessagesFromOtherUsers($uid, $threads);
if (empty($thread_last_messages)) {
return $unread;
}

// Check if someone send a message after your last check.
if ($last_message > $thread_last_check) {
$unread++;
foreach ($thread_last_messages as $thread_id => $last_message) {
// Check if the user has a timestamp on the thread.
$thread_last_check = $this->userData->get('private_message', $uid, 'private_message_thread:' . $thread_id);
if ($thread_last_check === NULL) {
$thread_last_check = 0;
}

// Check if someone send a message after your last check.
if ($last_message > $thread_last_check) {
$unread++;
}
}
}

return $unread;
}

Expand Down