]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3164. Denormalized unread message counting query because it was making things...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 19 Mar 2011 03:48:37 +0000 (03:48 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 19 Mar 2011 03:48:37 +0000 (03:48 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8763 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/messages/start.php

index 5c4081a7b203b152e89e525b5a07ec1f1c7d539f..bf8272b1ab524c1c36293b71c1232a920f34400d 100644 (file)
@@ -316,15 +316,38 @@ function count_unread_messages() {
  * @return int
  */
 function messages_count_unread() {
+       $user_guid = elgg_get_logged_in_user_guid();
+       $db_prefix = elgg_get_config('dbprefix');
+
+       // denormalize the md to speed things up.
+       // seriously, 10 joins if you don't.
+       $strings = array('toId', $user_guid, 'readYet', 0, 'msg', 1);
+       $map = array();
+       foreach ($strings as $string) {
+               $id = get_metastring_id($string);
+               $map[$string] = $id;
+       }
 
        $options = array(
-               'metadata_name_value_pairs' => array(
-                       'toId' => elgg_get_logged_in_user_guid(),
-                       'readYet' => 0,
-                       'msg' => 1
+//             'metadata_name_value_pairs' => array(
+//                     'toId' => elgg_get_logged_in_user_guid(),
+//                     'readYet' => 0,
+//                     'msg' => 1
+//             ),
+               'joins' => array(
+                       "JOIN {$db_prefix}metadata msg_toId on e.guid = msg_toId.entity_guid",
+                       "JOIN {$db_prefix}metadata msg_readYet on e.guid = msg_readYet.entity_guid",
+                       "JOIN {$db_prefix}metadata msg_msg on e.guid = msg_msg.entity_guid",
+               ),
+               'wheres' => array(
+                       "msg_toId.name_id='{$map['toId']}' AND msg_toId.value_id='{$map[$user_guid]}'",
+                       "msg_readYet.name_id='{$map['readYet']}' AND msg_readYet.value_id='{$map[0]}'",
+                       "msg_msg.name_id='{$map['msg']}' AND msg_msg.value_id='{$map[1]}'",
                ),
-               'owner_guid' => elgg_get_logged_in_user_guid()
+               'owner_guid' => $user_guid,
+               'limit' => 0
        );
+
        $num_messages = elgg_get_entities_from_metadata($options);
 
        if (is_array($num_messages)) {