From 07657e501153b4a0108384a23126ebab404c195c Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Tue, 8 Jun 2010 16:25:21 -0400 Subject: [PATCH] Reworked active messages SQL. Fixes #11594. Don't try to relate to groups that the user may not be a part of any longer. --- lib/WebGUI/Inbox.pm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/WebGUI/Inbox.pm b/lib/WebGUI/Inbox.pm index 6b5e4f5d2..24d08d699 100644 --- a/lib/WebGUI/Inbox.pm +++ b/lib/WebGUI/Inbox.pm @@ -483,7 +483,7 @@ sub getMessageSql { } if($whereClause) { - $whereClause = qq{WHERE $whereClause}; + $whereClause = qq{AND $whereClause}; } if($limit) { @@ -508,14 +508,13 @@ SELECT my $sql = qq{ SELECT $select - FROM ( - ( SELECT messageId, subject, sentBy, dateStamp, status FROM inbox WHERE userId = '$userId' order by dateStamp desc limit $limitHalf) - UNION - ( SELECT messageId, subject, sentBy, dateStamp, status FROM inbox WHERE groupId IN ( $userGroups ) order by dateStamp desc limit $limitHalf ) - ) AS ibox - JOIN inbox_messageState on inbox_messageState.messageId=ibox.messageId and inbox_messageState.userId='$userId' and inbox_messageState.deleted=0 - LEFT JOIN users on users.userId=ibox.sentBy - LEFT JOIN userProfileData on userProfileData.userId=ibox.sentBy + FROM inbox_messageState + JOIN inbox ibox USING (messageId) + JOIN users on users.userId = ibox.sentBy + JOIN userProfileData on userProfileData.userId = ibox.sentBy + WHERE inbox_messageState.messageId = ibox.messageId + AND inbox_messageState.userId = '$userId' + AND inbox_messageState.deleted = 0 $whereClause $sortBy $limit