Some more database stuff

This commit is contained in:
Michael 2017-01-15 12:36:06 +00:00
parent e16afc0450
commit 021a4fad71
7 changed files with 24 additions and 34 deletions

View file

@ -59,7 +59,6 @@ CREATE TABLE IF NOT EXISTS `cache` (
`expire_mode` int(11) NOT NULL DEFAULT 0, `expire_mode` int(11) NOT NULL DEFAULT 0,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`k`), PRIMARY KEY(`k`),
INDEX `updated` (`updated`),
INDEX `expire_mode_updated` (`expire_mode`,`updated`) INDEX `expire_mode_updated` (`expire_mode`,`updated`)
) DEFAULT CHARSET=utf8mb4; ) DEFAULT CHARSET=utf8mb4;
@ -183,7 +182,9 @@ CREATE TABLE IF NOT EXISTS `contact` (
INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)), INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
INDEX `addr_uid` (`addr`(32),`uid`), INDEX `addr_uid` (`addr`(32),`uid`),
INDEX `nurl_uid` (`nurl`(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; ) DEFAULT CHARSET=utf8mb4;
-- --
@ -264,7 +265,8 @@ CREATE TABLE IF NOT EXISTS `fcontact` (
`pubkey` text, `pubkey` text,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
INDEX `addr` (`addr`(32)) INDEX `addr` (`addr`(32)),
INDEX `url` (`url`)
) DEFAULT CHARSET=utf8mb4; ) DEFAULT CHARSET=utf8mb4;
-- --
@ -353,6 +355,7 @@ CREATE TABLE IF NOT EXISTS `gcontact` (
INDEX `name` (`name`(32)), INDEX `name` (`name`(32)),
INDEX `nick` (`nick`(32)), INDEX `nick` (`nick`(32)),
INDEX `addr` (`addr`(32)), INDEX `addr` (`addr`(32)),
INDEX `hide_network_updated` (`hide`,`network`,`updated`),
INDEX `updated` (`updated`) INDEX `updated` (`updated`)
) DEFAULT CHARSET=utf8mb4; ) DEFAULT CHARSET=utf8mb4;
@ -368,8 +371,7 @@ CREATE TABLE IF NOT EXISTS `glink` (
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
UNIQUE INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`), UNIQUE INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`),
INDEX `gcid` (`gcid`), INDEX `gcid` (`gcid`)
INDEX `zcid` (`zcid`)
) DEFAULT CHARSET=utf8mb4; ) DEFAULT CHARSET=utf8mb4;
-- --
@ -394,8 +396,8 @@ CREATE TABLE IF NOT EXISTS `group_member` (
`gid` int(10) unsigned NOT NULL DEFAULT 0, `gid` int(10) unsigned NOT NULL DEFAULT 0,
`contact-id` int(10) unsigned NOT NULL DEFAULT 0, `contact-id` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
INDEX `contactid` (`contact-id`),
INDEX `gid_contactid` (`gid`,`contact-id`), INDEX `gid_contactid` (`gid`,`contact-id`),
INDEX `uid_contactid` (`uid`,`contact-id`),
UNIQUE INDEX `uid_gid_contactid` (`uid`,`gid`,`contact-id`) UNIQUE INDEX `uid_gid_contactid` (`uid`,`gid`,`contact-id`)
) DEFAULT CHARSET=utf8mb4; ) DEFAULT CHARSET=utf8mb4;
@ -532,18 +534,13 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `uid_created` (`uid`,`created`), INDEX `uid_created` (`uid`,`created`),
INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`), INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
INDEX `uid_network_received` (`uid`,`network`,`received`), INDEX `uid_network_received` (`uid`,`network`,`received`),
INDEX `uid_received` (`uid`,`received`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`), INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_title` (`uid`,`title`),
INDEX `uid_thrparent` (`uid`,`thr-parent`), INDEX `uid_thrparent` (`uid`,`thr-parent`),
INDEX `uid_parenturi` (`uid`,`parent-uri`), INDEX `uid_parenturi` (`uid`,`parent-uri`),
INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
INDEX `authorid_created` (`author-id`,`created`), INDEX `authorid_created` (`author-id`,`created`),
INDEX `uid_uri` (`uid`,`uri`), INDEX `uid_uri` (`uid`,`uri`),
INDEX `uid_wall_created` (`uid`,`wall`,`created`),
INDEX `resource-id` (`resource-id`), 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 `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 `uid_type_changed` (`uid`,`type`,`changed`),
INDEX `contactid_verb` (`contact-id`,`verb`), INDEX `contactid_verb` (`contact-id`,`verb`),
@ -603,7 +600,6 @@ CREATE TABLE IF NOT EXISTS `mail` (
`parent-uri` varchar(255) NOT NULL DEFAULT '', `parent-uri` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
INDEX `uid` (`uid`),
INDEX `uid_seen` (`uid`,`seen`), INDEX `uid_seen` (`uid`,`seen`),
INDEX `convid` (`convid`), INDEX `convid` (`convid`),
INDEX `uri` (`uri`(64)), INDEX `uri` (`uri`(64)),
@ -638,7 +634,7 @@ CREATE TABLE IF NOT EXISTS `manage` (
`uid` int(11) NOT NULL DEFAULT 0, `uid` int(11) NOT NULL DEFAULT 0,
`mid` int(11) NOT NULL DEFAULT 0, `mid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
INDEX `uid_mid` (`uid`,`mid`) UNIQUE INDEX `uid_mid` (`uid`,`mid`)
) DEFAULT CHARSET=utf8mb4; ) DEFAULT CHARSET=utf8mb4;
-- --
@ -663,11 +659,10 @@ CREATE TABLE IF NOT EXISTS `notify` (
`name_cache` tinytext, `name_cache` tinytext,
`msg_cache` mediumtext, `msg_cache` mediumtext,
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
INDEX `uid_hash` (`uid`,`hash`), INDEX `hash_uid` (`hash`,`uid`),
INDEX `uid_seen_date` (`uid`,`seen`,`date`), INDEX `seen_uid_date` (`seen`,`uid`,`date`),
INDEX `uid_type_link` (`uid`,`type`,`link`), INDEX `uid_date` (`uid`,`date`),
INDEX `uid_link` (`uid`,`link`), INDEX `uid_type_link` (`uid`,`type`,`link`)
INDEX `uid_date` (`uid`,`date`)
) DEFAULT CHARSET=utf8mb4; ) DEFAULT CHARSET=utf8mb4;
-- --
@ -679,8 +674,7 @@ CREATE TABLE IF NOT EXISTS `notify-threads` (
`master-parent-item` int(10) unsigned NOT NULL DEFAULT 0, `master-parent-item` int(10) unsigned NOT NULL DEFAULT 0,
`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, `receiver-uid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`), PRIMARY KEY(`id`)
INDEX `master-parent-item` (`master-parent-item`)
) DEFAULT CHARSET=utf8mb4; ) DEFAULT CHARSET=utf8mb4;
-- --
@ -749,7 +743,6 @@ CREATE TABLE IF NOT EXISTS `photo` (
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
INDEX `uid_contactid` (`uid`,`contact-id`), INDEX `uid_contactid` (`uid`,`contact-id`),
INDEX `uid_profile` (`uid`,`profile`), 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_scale_created` (`uid`,`album`(32),`scale`,`created`),
INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`(64),`created`), INDEX `uid_album_resource-id_created` (`uid`,`album`(32),`resource-id`(64),`created`),
INDEX `resource-id` (`resource-id`(64)) INDEX `resource-id` (`resource-id`(64))
@ -844,7 +837,8 @@ CREATE TABLE IF NOT EXISTS `profile` (
`thumb` varchar(255) NOT NULL DEFAULT '', `thumb` varchar(255) NOT NULL DEFAULT '',
`publish` tinyint(1) NOT NULL DEFAULT 0, `publish` tinyint(1) NOT NULL DEFAULT 0,
`net-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; ) DEFAULT CHARSET=utf8mb4;
-- --
@ -980,8 +974,6 @@ CREATE TABLE IF NOT EXISTS `term` (
`uid` int(10) unsigned NOT NULL DEFAULT 0, `uid` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`tid`), PRIMARY KEY(`tid`),
INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`), 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_term_global_created` (`uid`,`otype`,`type`,`term`(32),`global`,`created`),
INDEX `uid_otype_type_url` (`uid`,`otype`,`type`,`url`(64)), INDEX `uid_otype_type_url` (`uid`,`otype`,`type`,`url`(64)),
INDEX `guid` (`guid`(64)) INDEX `guid` (`guid`(64))
@ -1018,8 +1010,6 @@ CREATE TABLE IF NOT EXISTS `thread` (
`mention` tinyint(1) NOT NULL DEFAULT 0, `mention` tinyint(1) NOT NULL DEFAULT 0,
`network` varchar(32) NOT NULL DEFAULT '', `network` varchar(32) NOT NULL DEFAULT '',
PRIMARY KEY(`iid`), PRIMARY KEY(`iid`),
INDEX `created` (`created`),
INDEX `commented` (`commented`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`), INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_network_created` (`uid`,`network`,`created`), INDEX `uid_network_created` (`uid`,`network`,`created`),
INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`), 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', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`pid` int(11) NOT NULL DEFAULT 0, `pid` int(11) NOT NULL DEFAULT 0,
`executed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `executed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`), PRIMARY KEY(`id`)
INDEX `created` (`created`)
) DEFAULT CHARSET=utf8mb4; ) DEFAULT CHARSET=utf8mb4;

View file

@ -181,7 +181,7 @@ class dba {
if ($log) { if ($log) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
@file_put_contents($a->config["system"]["db_log_index"], datetime_convert()."\t". @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". basename($backtrace[1]["file"])."\t".
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
substr($query, 0, 2000)."\n", FILE_APPEND); substr($query, 0, 2000)."\n", FILE_APPEND);

View file

@ -958,7 +958,6 @@ function db_definition($charset) {
"contactid_verb" => array("contact-id","verb"), "contactid_verb" => array("contact-id","verb"),
"deleted_changed" => array("deleted","changed"), "deleted_changed" => array("deleted","changed"),
"uid_wall_changed" => array("uid","wall","changed"), "uid_wall_changed" => array("uid","wall","changed"),
"wall_uid_changed" => array("wall","uid","changed"),
"uid_eventid" => array("uid","event-id"), "uid_eventid" => array("uid","event-id"),
"uid_authorlink" => array("uid","author-link"), "uid_authorlink" => array("uid","author-link"),
"uid_ownerlink" => array("uid","owner-link"), "uid_ownerlink" => array("uid","owner-link"),

View file

@ -194,7 +194,7 @@ class dfrn {
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`, `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer` `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` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND (NOT `contact`.`blocked` OR `contact`.`pending`) AND (NOT `contact`.`blocked` OR `contact`.`pending`)
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`

View file

@ -523,7 +523,9 @@ class ostatus {
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
intval($importer["uid"]), dbesc($item["parent-uri"])); 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"; $reply_path = str_replace("/notice/", "/api/statuses/show/", $related).".atom";
if ($reply_path != $related) { if ($reply_path != $related) {

View file

@ -239,7 +239,7 @@ function post_update_1206() {
logger("Start", LOGGER_DEBUG); logger("Start", LOGGER_DEBUG);
$r = q("SELECT `contact`.`id`, `contact`.`last-item`, $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` FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`"); INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`");

View file

@ -1529,7 +1529,7 @@ function get_gcontact_id($contact) {
if (in_array($contact["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) if (in_array($contact["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
$contact["url"] = clean_contact_url($contact["url"]); $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"]))); dbesc(normalise_link($contact["url"])));
if ($r) { if ($r) {