Merge pull request #2351 from annando/1602-performance-unread-group
Optimized query for unread group postings
This commit is contained in:
commit
d0b5c16a20
2 changed files with 21 additions and 20 deletions
|
@ -215,7 +215,7 @@ function mini_group_select($uid,$gid = 0) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create group sidebar widget
|
* @brief Create group sidebar widget
|
||||||
*
|
*
|
||||||
* @param string $every
|
* @param string $every
|
||||||
* @param string $each
|
* @param string $each
|
||||||
* @param string $editmode
|
* @param string $editmode
|
||||||
|
@ -234,7 +234,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
$groups = array();
|
$groups = array();
|
||||||
|
|
||||||
$groups[] = array(
|
$groups[] = array(
|
||||||
'text' => t('Everybody'),
|
'text' => t('Everybody'),
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
|
@ -255,7 +255,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
||||||
if(count($r)) {
|
if(count($r)) {
|
||||||
foreach($r as $rr) {
|
foreach($r as $rr) {
|
||||||
$selected = (($group_id == $rr['id']) ? ' group-selected' : '');
|
$selected = (($group_id == $rr['id']) ? ' group-selected' : '');
|
||||||
|
|
||||||
if ($editmode == "full") {
|
if ($editmode == "full") {
|
||||||
$groupedit = array(
|
$groupedit = array(
|
||||||
'href' => "group/".$rr['id'],
|
'href' => "group/".$rr['id'],
|
||||||
|
@ -264,7 +264,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
||||||
} else {
|
} else {
|
||||||
$groupedit = null;
|
$groupedit = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$groups[] = array(
|
$groups[] = array(
|
||||||
'id' => $rr['id'],
|
'id' => $rr['id'],
|
||||||
'cid' => $cid,
|
'cid' => $cid,
|
||||||
|
@ -362,14 +362,13 @@ function groups_containing($uid,$c) {
|
||||||
*/
|
*/
|
||||||
function groups_count_unseen() {
|
function groups_count_unseen() {
|
||||||
|
|
||||||
$r = q("SELECT `group`.`id`, `group`.`name`, COUNT(`item`.`id`) AS `count` FROM `group`, `group_member`, `item`
|
$r = q("SELECT `group`.`id`, `group`.`name`,
|
||||||
WHERE `group`.`uid` = %d
|
(SELECT COUNT(*) FROM `item`
|
||||||
AND `item`.`uid` = %d
|
WHERE `uid` = %d AND `unseen` AND
|
||||||
AND `item`.`unseen` AND `item`.`visible`
|
`contact-id` IN (SELECT `contact-id` FROM `group_member`
|
||||||
AND NOT `item`.`deleted`
|
WHERE `group_member`.`gid` = `group`.`id` AND `group_member`.`uid` = %d)) AS `count`
|
||||||
AND `item`.`contact-id` = `group_member`.`contact-id`
|
FROM `group` WHERE `group`.`uid` = %d;",
|
||||||
AND `group_member`.`gid` = `group`.`id`
|
intval(local_user()),
|
||||||
GROUP BY `group`.`id` ",
|
|
||||||
intval(local_user()),
|
intval(local_user()),
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
|
|
18
mod/ping.php
18
mod/ping.php
|
@ -219,19 +219,21 @@ function ping_init(&$a) {
|
||||||
<home>$home</home>\r\n";
|
<home>$home</home>\r\n";
|
||||||
if ($register!=0) echo "<register>$register</register>";
|
if ($register!=0) echo "<register>$register</register>";
|
||||||
|
|
||||||
if ( count($groups_unseen) ) {
|
if (count($groups_unseen)) {
|
||||||
echo '<groups>';
|
echo '<groups>';
|
||||||
foreach ($groups_unseen as $it) {
|
foreach ($groups_unseen as $it)
|
||||||
echo '<group id="' . $it['id'] . '">' . $it['count'] . "</group>";
|
if ($it['count'] > 0)
|
||||||
}
|
echo '<group id="'.$it['id'].'">'.$it['count']."</group>";
|
||||||
|
|
||||||
echo "</groups>";
|
echo "</groups>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count($forums_unseen) ) {
|
if (count($forums_unseen)) {
|
||||||
echo '<forums>';
|
echo '<forums>';
|
||||||
foreach ($forums_unseen as $it) {
|
foreach ($forums_unseen as $it)
|
||||||
echo '<forum id="' . $it['id'] . '">' . $it['count'] . "</forum>";
|
if ($it['count'] > 0)
|
||||||
}
|
echo '<forum id="'.$it['id'].'">'.$it['count']."</forum>";
|
||||||
|
|
||||||
echo "</forums>";
|
echo "</forums>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue