]> git.mxchange.org Git - friendica.git/commitdiff
Some more database stuff
authorMichael <heluecht@pirati.ca>
Sun, 15 Jan 2017 12:36:06 +0000 (12:36 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 15 Jan 2017 12:36:06 +0000 (12:36 +0000)
database.sql
include/dba.php
include/dbstructure.php
include/dfrn.php
include/ostatus.php
include/post_update.php
include/socgraph.php

index c07d2ae6d93af14e0cdfbb4c9c808b08fbc8a916..9d4d289f2fa52efc735ebbbba4599dc69dd2ec9d 100644 (file)
@@ -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;
 
index 4b76f55ab0a0f6503c319c274c3a6bda52faafba..7d2d3bbd0f6d01ae59e481b70848ec8f2ba7aa07 100644 (file)
@@ -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);
index 551f254a536beec833e3b9e0c15ec05663a226fb..6154ddeb08a5f916dc3b809b1cbad1fe53eef193 100644 (file)
@@ -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"),
index 5e4f03779682e71367638fe9325170e5a25ad418..ffdc2cbaf9b66424598e74ddae883743bee01293 100644 (file)
@@ -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`
index ba64f493dbad9d6addacc1884237627440a17a7d..2c4b677a53af99bf5316cc9ca8caa8a512ac5802 100644 (file)
@@ -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) {
index b2d682d722545386b3e180fa300257bca17ee12d..ae5aad26daaa87a9950b61f56ad7391b5fad8d8a 100644 (file)
@@ -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`");
 
index 6249f189e9a0a0d30c0b44cfa4fa78fd95ba86ec..32c151c0431dace3e4951edb1c110f679e7f20dc 100644 (file)
@@ -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) {