The count on the invites page and upper right notification icon is incorrect.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ezra-g’s picture

Component: Code » Trusted Contacts and Private Messaging
jpontani’s picture

I can't reproduce it directly, but can see how it could happen in theory. The value displayed in both the tab count and the upper right corner icon are the values stored in the field_unread_messages/field_unread_invitations fields. If those get out of sync with the actual values, or somehow cached, then it will show incorrect values. I did a test by changing the tab/icon counts to do the same method that is used for getting the trusted contacts count, which is to grab the view, execute it, and show the total results.

IE, this part:

  $view = views_get_view('trusted_contacts');
  $view->get_total_rows = TRUE;
  $view->execute();
  $tabs['contacts'] = array(
    'title' => t('Trusted Contacts') . ' <span class="commons-bw-result-count">'. $view->total_rows . '</span>',
    'contents' => views_embed_view('trusted_contacts'),
  );

  $wrapper = entity_metadata_wrapper('user', $user);
  $tabs['messages'] = array(
    'title' => t('Messages') . ' <span class="commons-bw-result-count">'. (int)$wrapper->field_unread_messages->value() . '</span>',
    'contents' => privatemsg_list_page(),
  );
ezra-g’s picture

Thanks, jpontani! I asked amitaibu to comment on the proposed approach here. I suspect the concern was around render time for the views. Some profiling might help inform us here.

amitaibu’s picture

Keeping a field Vs on the fly is mostly a matter of taste, and since it's a value that appears on every single page I preferred keeping it in a field. However on the fly calculation of messages would probably not be Commons' performance bottle neck ;)

Anyway, Views IMO shouldn't be use - it's an overkill just to get a number. db_query() would be much nicer.

ezra-g’s picture

Status: Active » Postponed (maintainer needs more info)

Can we get steps to reproduce this?

ezra-g’s picture

Priority: Normal » Major
ezra-g’s picture

Assigned: Unassigned » ezra-g
ezra-g’s picture

This patch defines a new helper function: commons_trusted_contacts_get_pending_invitations(), and uses the existing privatemsg_unread_count(), and replaces and removes the unread count fields.

ezra-g’s picture

Status: Postponed (maintainer needs more info) » Needs review
svajlenka’s picture

I was experiencing this issue and the patch in #9 worked for me.

ezra-g’s picture

Automatically closed -- issue fixed for 2 weeks with no activity.