aboutsummaryrefslogtreecommitdiff
path: root/mod/messages
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-03-19 03:48:37 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-03-19 03:48:37 +0000
commit0331c8f714e7c1af6d4a871cd37f491180668855 (patch)
treecd36c96fcd933cd31120bdc3ae681038db61346a /mod/messages
parentad5fe640659b720ab329d4b06747c1b3bfe74d97 (diff)
downloadelgg-0331c8f714e7c1af6d4a871cd37f491180668855.tar.gz
elgg-0331c8f714e7c1af6d4a871cd37f491180668855.tar.bz2
Fixes #3164. Denormalized unread message counting query because it was making things so slow I couldn't test.
git-svn-id: http://code.elgg.org/elgg/trunk@8763 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/messages')
-rw-r--r--mod/messages/start.php33
1 files changed, 28 insertions, 5 deletions
diff --git a/mod/messages/start.php b/mod/messages/start.php
index 5c4081a7b..bf8272b1a 100644
--- a/mod/messages/start.php
+++ b/mod/messages/start.php
@@ -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)) {