public function setSeen($note, $seen = true)
{
return q(
- "UPDATE `notify` SET `seen` = %d WHERE ( `link` = '%s' OR ( `parent` != 0 AND `parent` = %d AND `otype` = '%s' )) AND `uid` = %d",
+ "UPDATE `notify` SET `seen` = %d WHERE (`link` = '%s' OR (`parent` != 0 AND `parent` = %d AND `otype` = '%s')) AND `uid` = %d",
intval($seen),
dbesc($note['link']),
intval($note['parent']),
private function networkTotal($seen = 0)
{
$sql_seen = "";
+ $index_hint = "";
if ($seen === 0) {
- $sql_seen = " AND `item`.`unseen` = 1 ";
+ $sql_seen = " AND `item`.`unseen` ";
+ $index_hint = "USE INDEX (`uid_unseen_contactid`)";
}
$r = q(
"SELECT COUNT(*) AS `total`
- FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
- WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
- `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
+ FROM `item` $index_hint STRAIGHT_JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
+ WHERE `item`.`visible` AND `pitem`.`parent` != 0 AND
+ NOT `item`.`deleted` AND `item`.`uid` = %d AND NOT `item`.`wall`
$sql_seen",
intval(local_user())
);
$total = $this->networkTotal($seen);
$notifs = [];
$sql_seen = "";
+ $index_hint = "";
if ($seen === 0) {
- $sql_seen = " AND `item`.`unseen` = 1 ";
+ $sql_seen = " AND `item`.`unseen` ";
+ $index_hint = "USE INDEX (`uid_unseen_contactid`)";
}
$r = q(
"SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
- FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
- WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
- `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
+ FROM `item` $index_hint STRAIGHT_JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
+ WHERE `item`.`visible` AND `pitem`.`parent` != 0 AND
+ NOT `item`.`deleted` AND `item`.`uid` = %d AND NOT `item`.`wall`
$sql_seen
ORDER BY `item`.`created` DESC LIMIT %d, %d ",
intval(local_user()),
$sql_seen = "";
if ($seen === 0) {
- $sql_seen = " AND `seen` = 0 ";
+ $sql_seen = " AND NOT `seen` ";
}
$r = q(
$sql_seen = "";
if ($seen === 0) {
- $sql_seen = " AND `seen` = 0 ";
+ $sql_seen = " AND NOT `seen` ";
}
$r = q(
$myurl = str_replace(['www.', '.'], ['', '\\.'], $myurl);
$diasp_url = str_replace('/profile/', '/u/', $myurl);
$sql_extra = sprintf(
- " AND ( `item`.`author-link` regexp '%s' OR `item`.`tag` regexp '%s' OR `item`.`tag` regexp '%s' ) ",
+ " AND (`item`.`author-link` REGEXP '%s' OR `item`.`tag` REGEXP '%s' OR `item`.`tag` REGEXP '%s') ",
dbesc($myurl . '$'),
dbesc($myurl . '\\]'),
dbesc($diasp_url . '\\]')
private function personalTotal($seen = 0)
{
$sql_seen = "";
+ $index_hint = "";
$sql_extra = $this->personalSqlExtra();
if ($seen === 0) {
- $sql_seen = " AND `item`.`unseen` = 1 ";
+ $sql_seen = " AND `item`.`unseen` ";
+ $index_hint = "USE INDEX (`uid_unseen_contactid`)";
}
$r = q(
"SELECT COUNT(*) AS `total`
- FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
- WHERE `item`.`visible` = 1
+ FROM `item` $index_hint
+ WHERE `item`.`visible`
$sql_extra
$sql_seen
- AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ",
+ AND NOT `item`.`deleted` AND `item`.`uid` = %d AND NOT `item`.`wall`",
intval(local_user())
);
if (DBM::is_result($r)) {
$sql_extra = $this->personalSqlExtra();
$notifs = [];
$sql_seen = "";
+ $index_hint = "";
if ($seen === 0) {
- $sql_seen = " AND `item`.`unseen` = 1 ";
+ $sql_seen = " AND `item`.`unseen` ";
+ $index_hint = "USE INDEX (`uid_unseen_contactid`)";
}
$r = q(
"SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
- FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
- WHERE `item`.`visible` = 1
+ FROM `item` $index_hint STRAIGHT_JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
+ WHERE `item`.`visible`
$sql_extra
$sql_seen
- AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
+ AND NOT `item`.`deleted` AND `item`.`uid` = %d AND NOT `item`.`wall`
ORDER BY `item`.`created` DESC LIMIT %d, %d ",
intval(local_user()),
intval($start),
private function homeTotal($seen = 0)
{
$sql_seen = "";
+ $index_hint = "";
if ($seen === 0) {
- $sql_seen = " AND `item`.`unseen` = 1 ";
+ $sql_seen = " AND `item`.`unseen` ";
+ $index_hint = "USE INDEX (`uid_unseen_contactid`)";
}
$r = q(
- "SELECT COUNT(*) AS `total` FROM `item`
+ "SELECT COUNT(*) AS `total` FROM `item` $index_hint
WHERE `item`.`visible` = 1 AND
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
$sql_seen",
$total = $this->homeTotal($seen);
$notifs = [];
$sql_seen = "";
+ $index_hint = "";
if ($seen === 0) {
- $sql_seen = " AND `item`.`unseen` = 1 ";
+ $sql_seen = " AND `item`.`unseen` ";
+ $index_hint = "USE INDEX (`uid_unseen_contactid`)";
}
$r = q(
"SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
- FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
- WHERE `item`.`visible` = 1 AND
- `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
+ FROM `item` $index_hint STRAIGHT_JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
+ WHERE `item`.`visible` AND
+ NOT `item`.`deleted` AND `item`.`uid` = %d AND `item`.`wall`
$sql_seen
ORDER BY `item`.`created` DESC LIMIT %d, %d ",
intval(local_user()),