Merge pull request #2351 from annando/1602-performance-unread-group
Optimized query for unread group postings
This commit is contained in:
commit
d0b5c16a20
|
@ -362,14 +362,13 @@ function groups_containing($uid,$c) {
|
|||
*/
|
||||
function groups_count_unseen() {
|
||||
|
||||
$r = q("SELECT `group`.`id`, `group`.`name`, COUNT(`item`.`id`) AS `count` FROM `group`, `group_member`, `item`
|
||||
WHERE `group`.`uid` = %d
|
||||
AND `item`.`uid` = %d
|
||||
AND `item`.`unseen` AND `item`.`visible`
|
||||
AND NOT `item`.`deleted`
|
||||
AND `item`.`contact-id` = `group_member`.`contact-id`
|
||||
AND `group_member`.`gid` = `group`.`id`
|
||||
GROUP BY `group`.`id` ",
|
||||
$r = q("SELECT `group`.`id`, `group`.`name`,
|
||||
(SELECT COUNT(*) FROM `item`
|
||||
WHERE `uid` = %d AND `unseen` AND
|
||||
`contact-id` IN (SELECT `contact-id` FROM `group_member`
|
||||
WHERE `group_member`.`gid` = `group`.`id` AND `group_member`.`uid` = %d)) AS `count`
|
||||
FROM `group` WHERE `group`.`uid` = %d;",
|
||||
intval(local_user()),
|
||||
intval(local_user()),
|
||||
intval(local_user())
|
||||
);
|
||||
|
|
10
mod/ping.php
10
mod/ping.php
|
@ -221,17 +221,19 @@ function ping_init(&$a) {
|
|||
|
||||
if (count($groups_unseen)) {
|
||||
echo '<groups>';
|
||||
foreach ($groups_unseen as $it) {
|
||||
foreach ($groups_unseen as $it)
|
||||
if ($it['count'] > 0)
|
||||
echo '<group id="'.$it['id'].'">'.$it['count']."</group>";
|
||||
}
|
||||
|
||||
echo "</groups>";
|
||||
}
|
||||
|
||||
if (count($forums_unseen)) {
|
||||
echo '<forums>';
|
||||
foreach ($forums_unseen as $it) {
|
||||
foreach ($forums_unseen as $it)
|
||||
if ($it['count'] > 0)
|
||||
echo '<forum id="'.$it['id'].'">'.$it['count']."</forum>";
|
||||
}
|
||||
|
||||
echo "</forums>";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue