From 021a4fad714c25c9e031ff4792ba0e2b7377568b Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 15 Jan 2017 12:36:06 +0000 Subject: [PATCH] Some more database stuff --- database.sql | 45 ++++++++++++++++------------------------- include/dba.php | 2 +- include/dbstructure.php | 1 - include/dfrn.php | 2 +- include/ostatus.php | 4 +++- include/post_update.php | 2 +- include/socgraph.php | 2 +- 7 files changed, 24 insertions(+), 34 deletions(-) diff --git a/database.sql b/database.sql index c07d2ae6d9..9d4d289f2f 100644 --- a/database.sql +++ b/database.sql @@ -59,7 +59,6 @@ CREATE TABLE IF NOT EXISTS `cache` ( `expire_mode` int(11) NOT NULL DEFAULT 0, `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY(`k`), - INDEX `updated` (`updated`), INDEX `expire_mode_updated` (`expire_mode`,`updated`) ) DEFAULT CHARSET=utf8mb4; @@ -183,7 +182,9 @@ CREATE TABLE IF NOT EXISTS `contact` ( INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)), INDEX `addr_uid` (`addr`(32),`uid`), INDEX `nurl_uid` (`nurl`(32),`uid`), - INDEX `nick_uid` (`nick`(32),`uid`) + INDEX `nick_uid` (`nick`(32),`uid`), + INDEX `dfrn-id` (`dfrn-id`), + INDEX `issued-id` (`issued-id`) ) DEFAULT CHARSET=utf8mb4; -- @@ -264,7 +265,8 @@ CREATE TABLE IF NOT EXISTS `fcontact` ( `pubkey` text, `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY(`id`), - INDEX `addr` (`addr`(32)) + INDEX `addr` (`addr`(32)), + INDEX `url` (`url`) ) DEFAULT CHARSET=utf8mb4; -- @@ -353,6 +355,7 @@ CREATE TABLE IF NOT EXISTS `gcontact` ( INDEX `name` (`name`(32)), INDEX `nick` (`nick`(32)), INDEX `addr` (`addr`(32)), + INDEX `hide_network_updated` (`hide`,`network`,`updated`), INDEX `updated` (`updated`) ) DEFAULT CHARSET=utf8mb4; @@ -368,8 +371,7 @@ CREATE TABLE IF NOT EXISTS `glink` ( `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY(`id`), UNIQUE INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`), - INDEX `gcid` (`gcid`), - INDEX `zcid` (`zcid`) + INDEX `gcid` (`gcid`) ) DEFAULT CHARSET=utf8mb4; -- @@ -394,8 +396,8 @@ CREATE TABLE IF NOT EXISTS `group_member` ( `gid` int(10) unsigned NOT NULL DEFAULT 0, `contact-id` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY(`id`), + INDEX `contactid` (`contact-id`), INDEX `gid_contactid` (`gid`,`contact-id`), - INDEX `uid_contactid` (`uid`,`contact-id`), UNIQUE INDEX `uid_gid_contactid` (`uid`,`gid`,`contact-id`) ) DEFAULT CHARSET=utf8mb4; @@ -532,18 +534,13 @@ CREATE TABLE IF NOT EXISTS `item` ( INDEX `uid_created` (`uid`,`created`), INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`), INDEX `uid_network_received` (`uid`,`network`,`received`), - INDEX `uid_received` (`uid`,`received`), INDEX `uid_network_commented` (`uid`,`network`,`commented`), - INDEX `uid_title` (`uid`,`title`), INDEX `uid_thrparent` (`uid`,`thr-parent`), INDEX `uid_parenturi` (`uid`,`parent-uri`), - INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`), INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), INDEX `authorid_created` (`author-id`,`created`), INDEX `uid_uri` (`uid`,`uri`), - INDEX `uid_wall_created` (`uid`,`wall`,`created`), INDEX `resource-id` (`resource-id`), - INDEX `uid_type` (`uid`,`type`), INDEX `contactid_allowcid_allowpid_denycid_denygid` (`contact-id`,`allow_cid`(10),`allow_gid`(10),`deny_cid`(10),`deny_gid`(10)), INDEX `uid_type_changed` (`uid`,`type`,`changed`), INDEX `contactid_verb` (`contact-id`,`verb`), @@ -603,7 +600,6 @@ CREATE TABLE IF NOT EXISTS `mail` ( `parent-uri` varchar(255) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY(`id`), - INDEX `uid` (`uid`), INDEX `uid_seen` (`uid`,`seen`), INDEX `convid` (`convid`), INDEX `uri` (`uri`(64)), @@ -638,7 +634,7 @@ CREATE TABLE IF NOT EXISTS `manage` ( `uid` int(11) NOT NULL DEFAULT 0, `mid` int(11) NOT NULL DEFAULT 0, PRIMARY KEY(`id`), - INDEX `uid_mid` (`uid`,`mid`) + UNIQUE INDEX `uid_mid` (`uid`,`mid`) ) DEFAULT CHARSET=utf8mb4; -- @@ -663,11 +659,10 @@ CREATE TABLE IF NOT EXISTS `notify` ( `name_cache` tinytext, `msg_cache` mediumtext, PRIMARY KEY(`id`), - INDEX `uid_hash` (`uid`,`hash`), - INDEX `uid_seen_date` (`uid`,`seen`,`date`), - INDEX `uid_type_link` (`uid`,`type`,`link`), - INDEX `uid_link` (`uid`,`link`), - INDEX `uid_date` (`uid`,`date`) + INDEX `hash_uid` (`hash`,`uid`), + INDEX `seen_uid_date` (`seen`,`uid`,`date`), + INDEX `uid_date` (`uid`,`date`), + INDEX `uid_type_link` (`uid`,`type`,`link`) ) DEFAULT CHARSET=utf8mb4; -- @@ -679,8 +674,7 @@ CREATE TABLE IF NOT EXISTS `notify-threads` ( `master-parent-item` int(10) unsigned NOT NULL DEFAULT 0, `parent-item` int(10) unsigned NOT NULL DEFAULT 0, `receiver-uid` int(11) NOT NULL DEFAULT 0, - PRIMARY KEY(`id`), - INDEX `master-parent-item` (`master-parent-item`) + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8mb4; -- @@ -749,7 +743,6 @@ CREATE TABLE IF NOT EXISTS `photo` ( PRIMARY KEY(`id`), INDEX `uid_contactid` (`uid`,`contact-id`), INDEX `uid_profile` (`uid`,`profile`), - INDEX `uid_album_created` (`uid`,`album`(32),`created`), INDEX `uid_album_scale_created` (`uid`,`album`(32),`scale`,`created`), INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`(64),`created`), INDEX `resource-id` (`resource-id`(64)) @@ -844,7 +837,8 @@ CREATE TABLE IF NOT EXISTS `profile` ( `thumb` varchar(255) NOT NULL DEFAULT '', `publish` tinyint(1) NOT NULL DEFAULT 0, `net-publish` tinyint(1) NOT NULL DEFAULT 0, - PRIMARY KEY(`id`) + PRIMARY KEY(`id`), + INDEX `uid_is-default` (`uid`,`is-default`) ) DEFAULT CHARSET=utf8mb4; -- @@ -980,8 +974,6 @@ CREATE TABLE IF NOT EXISTS `term` ( `uid` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY(`tid`), INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`), - INDEX `uid_term_tid` (`uid`,`term`(32),`tid`), - INDEX `type_term` (`type`,`term`(32)), INDEX `uid_otype_type_term_global_created` (`uid`,`otype`,`type`,`term`(32),`global`,`created`), INDEX `uid_otype_type_url` (`uid`,`otype`,`type`,`url`(64)), INDEX `guid` (`guid`(64)) @@ -1018,8 +1010,6 @@ CREATE TABLE IF NOT EXISTS `thread` ( `mention` tinyint(1) NOT NULL DEFAULT 0, `network` varchar(32) NOT NULL DEFAULT '', PRIMARY KEY(`iid`), - INDEX `created` (`created`), - INDEX `commented` (`commented`), INDEX `uid_network_commented` (`uid`,`network`,`commented`), INDEX `uid_network_created` (`uid`,`network`,`created`), INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`), @@ -1112,7 +1102,6 @@ CREATE TABLE IF NOT EXISTS `workerqueue` ( `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `pid` int(11) NOT NULL DEFAULT 0, `executed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - PRIMARY KEY(`id`), - INDEX `created` (`created`) + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8mb4; diff --git a/include/dba.php b/include/dba.php index 4b76f55ab0..7d2d3bbd0f 100644 --- a/include/dba.php +++ b/include/dba.php @@ -181,7 +181,7 @@ class dba { if ($log) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); @file_put_contents($a->config["system"]["db_log_index"], datetime_convert()."\t". - $row['key']."\t".$row['rows']."\t". + $row['key']."\t".$row['rows']."\t".$row['Extra']."\t". basename($backtrace[1]["file"])."\t". $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". substr($query, 0, 2000)."\n", FILE_APPEND); diff --git a/include/dbstructure.php b/include/dbstructure.php index 551f254a53..6154ddeb08 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -958,7 +958,6 @@ function db_definition($charset) { "contactid_verb" => array("contact-id","verb"), "deleted_changed" => array("deleted","changed"), "uid_wall_changed" => array("uid","wall","changed"), - "wall_uid_changed" => array("wall","uid","changed"), "uid_eventid" => array("uid","event-id"), "uid_authorlink" => array("uid","author-link"), "uid_ownerlink" => array("uid","owner-link"), diff --git a/include/dfrn.php b/include/dfrn.php index 5e4f037796..ffdc2cbaf9 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -194,7 +194,7 @@ class dfrn { `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` USE INDEX (`uid_wall_changed`, `uid_type_changed`) $sql_post_table + FROM `item` USE INDEX (`uid_wall_changed`, `wall_uid_changed`) $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` diff --git a/include/ostatus.php b/include/ostatus.php index ba64f493db..2c4b677a53 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -523,7 +523,9 @@ class ostatus { $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($importer["uid"]), dbesc($item["parent-uri"])); - if (!$r AND ($related != "")) { + // Only fetch missing stuff if it is a comment or reshare. + if (in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_SHARE)) AND + !dbm::is_result($r) AND ($related != "")) { $reply_path = str_replace("/notice/", "/api/statuses/show/", $related).".atom"; if ($reply_path != $related) { diff --git a/include/post_update.php b/include/post_update.php index b2d682d722..ae5aad26da 100644 --- a/include/post_update.php +++ b/include/post_update.php @@ -239,7 +239,7 @@ function post_update_1206() { logger("Start", LOGGER_DEBUG); $r = q("SELECT `contact`.`id`, `contact`.`last-item`, - (SELECT MAX(`changed`) FROM `item` FORCE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date` + (SELECT MAX(`changed`) FROM `item` USE INDEX (`uid_wall_changed`, `wall_uid_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date` FROM `user` INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`"); diff --git a/include/socgraph.php b/include/socgraph.php index 6249f189e9..32c151c043 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1529,7 +1529,7 @@ function get_gcontact_id($contact) { if (in_array($contact["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) $contact["url"] = clean_contact_url($contact["url"]); - $r = q("SELECT `id`, `last_contact`, `last_failure`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 2", + $r = q("SELECT `id`, `last_contact`, `last_failure`, `network` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 2", dbesc(normalise_link($contact["url"]))); if ($r) {