diff --git a/include/api.php b/include/api.php index b93f8cf72a..af7c2ca523 100644 --- a/include/api.php +++ b/include/api.php @@ -565,9 +565,7 @@ //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", // count public wall messages - $r = q("SELECT count(*) as `count` FROM `item` - WHERE `uid` = %d - AND `type`='wall'", + $r = q("SELECT COUNT(*) as `count` FROM `item` WHERE `uid` = %d AND wall", intval($uinfo[0]['uid']) ); $countitms = $r[0]['count']; diff --git a/include/dbstructure.php b/include/dbstructure.php index f3c8947408..b28e072f9e 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1121,6 +1121,7 @@ function db_definition($charset) { "indexes" => array( "PRIMARY" => array("id"), "uid_contactid" => array("uid", "contact-id"), + "uid_profile" => array("uid", "profile"), "uid_album_created" => array("uid", "album", "created"), "resource-id" => array("resource-id"), "guid" => array("guid"), @@ -1356,6 +1357,7 @@ function db_definition($charset) { "type_term" => array("type","term"), "uid_otype_type_term_global_created" => array("uid","otype","type","term","global","created"), "otype_type_term_tid" => array("otype","type","term","tid"), + "uid_otype_type_url" => array("uid","otype","type","url"), "guid" => array("guid"), ) ); diff --git a/include/dfrn.php b/include/dfrn.php index 3b06932d8a..061991c4ca 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -193,13 +193,13 @@ class dfrn { // AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' ) // dbesc($check_date), - $r = q("SELECT STRAIGHT_JOIN `item`.*, `item`.`id` AS `item_id`, + $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`, `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `sign`.`signed_text`, `sign`.`signature`, `sign`.`signer` FROM `item` $sql_post_table - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`parent` != 0 diff --git a/include/items.php b/include/items.php index 0741e1b3d4..b969a75d6d 100644 --- a/include/items.php +++ b/include/items.php @@ -779,6 +779,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa logger('item_store: ' . print_r($arr,true), LOGGER_DATA); + q("COMMIT;"); + q("START TRANSACTION;"); + $r = dbq("INSERT INTO `item` (`" . implode("`, `", array_keys($arr)) . "`) VALUES ('" @@ -804,6 +807,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa dbesc($arr['network']), intval($r[0]["id"]) ); + q("COMMIT"); return 0; } elseif(count($r)) { @@ -813,6 +817,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa item_set_last_item($arr); } else { logger('item_store: could not locate created item'); + q("COMMIT"); return 0; } @@ -891,10 +896,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa create_tags_from_item($current_post); create_files_from_item($current_post); + q("COMMIT"); + // Only check for notifications on start posts - if ($arr['parent-uri'] === $arr['uri']) + if ($arr['parent-uri'] === $arr['uri']) { add_thread($current_post); - else { + } else { update_thread($parent_id); add_shadow_entry($arr); } diff --git a/include/onepoll.php b/include/onepoll.php index e779372720..951b87043e 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -443,7 +443,7 @@ function onepoll_run(&$argv, &$argc){ $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'"; } $qstr = implode(',',$refs_arr); - $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1", + $r = q("SELECT `uri` , `parent-uri` FROM `item` USE INDEX (`uid_uri`) WHERE `uri` IN ($qstr) AND `uid` = %d LIMIT 1", intval($importer_uid) ); if(count($r)) diff --git a/include/ostatus.php b/include/ostatus.php index ec53141dc7..556c81e987 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -806,11 +806,19 @@ class ostatus { } // Get the parent + $parents = q("SELECT `item`.`id`, `item`.`parent`, `item`.`uri`, `item`.`contact-id`, `item`.`type`, + `item`.`verb`, `item`.`visible` FROM `term` + STRAIGHT_JOIN `item` AS `thritem` ON `thritem`.`parent` = `term`.`oid` + STRAIGHT_JOIN `item` ON `item`.`parent` = `thritem`.`parent` + WHERE `term`.`uid` = %d AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`url` = '%s'))", + intval($uid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($conversation_url)); + +/* $parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN (SELECT `parent` FROM `item` WHERE `id` IN (SELECT `oid` FROM `term` WHERE `uid` = %d AND `otype` = %d AND `type` = %d AND `url` = '%s'))", intval($uid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($conversation_url)); - +*/ if ($parents) $parent = $parents[0]; elseif (count($item) > 0) { @@ -1961,9 +1969,21 @@ class ostatus { $last_update = 'now -30 days'; $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); + $authorid = get_contact($owner["url"], 0); - $items = q("SELECT STRAIGHT_JOIN `item`.*, `item`.`id` AS `item_id` FROM `item` - INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` + $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` USE INDEX (`uid_contactid_created`) + STRAIGHT_JOIN `thread` ON `thread`.`iid` = `item`.`parent` + WHERE `item`.`uid` = %d AND `item`.`contact-id` = %d AND + `item`.`author-id` = %d AND `item`.`created` > '%s' AND + NOT `item`.`deleted` AND NOT `item`.`private` AND + `thread`.`network` IN ('%s', '%s') + ORDER BY `item`.`created` DESC LIMIT 300", + intval($owner["uid"]), intval($owner["id"]), + intval($authorid), dbesc($check_date), + dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); +/* + $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` + STRAIGHT_JOIN `thread` ON `thread`.`iid` = `item`.`parent` LEFT JOIN `item` AS `thritem` ON `thritem`.`uri`=`item`.`thr-parent` AND `thritem`.`uid`=`item`.`uid` WHERE `item`.`uid` = %d AND `item`.`received` > '%s' AND NOT `item`.`private` AND NOT `item`.`deleted` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' @@ -1981,7 +2001,7 @@ class ostatus { dbesc($owner["nurl"]), dbesc(str_replace("http://", "https://", $owner["nurl"])), dbesc($owner["nurl"]), dbesc(str_replace("http://", "https://", $owner["nurl"])) ); - +*/ $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; diff --git a/mod/display.php b/mod/display.php index 0e0e7b3031..dcb9eb0941 100644 --- a/mod/display.php +++ b/mod/display.php @@ -27,9 +27,9 @@ function display_init(&$a) { // Or is it anywhere on the server? if ($nick == "") { - $r = qu("SELECT STRAIGHT_JOIN `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`, + $r = qu("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`, `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`owner-link`, `item`.`body` - FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid` + FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' @@ -236,7 +236,7 @@ function display_content(&$a, $update = 0) { } if ($nick == "") { - $r = qu("SELECT STRAIGHT_JOIN `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid` + $r = qu("SELECT `user`.`nickname`, `item`.`id` FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' diff --git a/mod/item.php b/mod/item.php index adc46f1208..94ff6b93d4 100644 --- a/mod/item.php +++ b/mod/item.php @@ -788,6 +788,9 @@ function item_post(&$a) { } else $post_id = 0; + q("COMMIT;"); + q("START TRANSACTION;"); + $r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`, `owner-name`,`owner-link`,`owner-avatar`, `owner-id`, `author-name`, `author-link`, `author-avatar`, `author-id`, @@ -864,6 +867,7 @@ function item_post(&$a) { $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($datarray['uri'])); if(!count($r)) { + q("COMMIT"); logger('mod_item: unable to retrieve post that was just stored.'); notice( t('System error. Post not saved.') . EOL); goaway($a->get_baseurl() . "/" . $return_path ); @@ -986,6 +990,8 @@ function item_post(&$a) { create_tags_from_item($post_id); create_files_from_item($post_id); + q("COMMIT"); + if ($post_id == $parent) add_thread($post_id); else { diff --git a/mod/photos.php b/mod/photos.php index 741181b2e9..ced9523e28 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -53,8 +53,8 @@ function photos_init(&$a) { $sql_extra = permissions_sql($a->data['user']['uid']); - $albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' - $sql_extra group by album order by created desc", + $albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` USE INDEX (`uid_album_created`) WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' + $sql_extra GROUP BY `album` ORDER BY `created` DESC", intval($a->data['user']['uid']), dbesc('Contact Photos'), dbesc( t('Contact Photos'))