]> git.mxchange.org Git - friendica.git/commitdiff
Conversation data is now stored in another table
authorMichael <heluecht@pirati.ca>
Wed, 26 Apr 2017 21:16:25 +0000 (21:16 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 26 Apr 2017 21:16:25 +0000 (21:16 +0000)
database.sql
include/dba.php
include/dbstructure.php
include/items.php
include/ostatus.php

index 69da511b0348763e279a5ca60ce1b788b5204779..e9a4ee2e4c2af206e22ed92a0ff786f6adcbc1fc 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 3.5.2-dev (Asparagus)
--- DB_UPDATE_VERSION 1219
+-- DB_UPDATE_VERSION 1220
 -- ------------------------------------------
 
 
@@ -174,13 +174,13 @@ CREATE TABLE IF NOT EXISTS `contact` (
        `fetch_further_information` tinyint(1) NOT NULL DEFAULT 0,
        `ffi_keyword_blacklist` text,
         PRIMARY KEY(`id`),
-        INDEX `uid_name` (`uid`,`name`),
+        INDEX `uid_name` (`uid`,`name`(190)),
         INDEX `self_uid` (`self`,`uid`),
         INDEX `alias_uid` (`alias`(32),`uid`),
         INDEX `pending_uid` (`pending`,`uid`),
         INDEX `blocked_uid` (`blocked`,`uid`),
-        INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`),
-        INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
+        INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`(4),`poll`(64),`archive`),
+        INDEX `uid_network_batch` (`uid`,`network`(4),`batch`(64)),
         INDEX `addr_uid` (`addr`(32),`uid`),
         INDEX `nurl_uid` (`nurl`(32),`uid`),
         INDEX `nick_uid` (`nick`(32),`uid`),
@@ -204,6 +204,19 @@ CREATE TABLE IF NOT EXISTS `conv` (
         INDEX `uid` (`uid`)
 ) DEFAULT COLLATE utf8mb4_general_ci;
 
+--
+-- TABLE conversation
+--
+CREATE TABLE IF NOT EXISTS `conversation` (
+       `item-uri` varbinary(255) NOT NULL,
+       `reply-to-uri` varbinary(255) NOT NULL DEFAULT '',
+       `conversation-uri` varbinary(255) NOT NULL DEFAULT '',
+       `protocol` tinyint(1) unsigned NOT NULL DEFAULT 0,
+       `source` mediumtext,
+        PRIMARY KEY(`item-uri`),
+        INDEX `conversation-uri` (`conversation-uri`)
+) DEFAULT COLLATE utf8mb4_general_ci;
+
 --
 -- TABLE event
 --
@@ -344,7 +357,7 @@ CREATE TABLE IF NOT EXISTS `gcontact` (
         INDEX `name` (`name`(64)),
         INDEX `nick` (`nick`(32)),
         INDEX `addr` (`addr`(64)),
-        INDEX `hide_network_updated` (`hide`,`network`,`updated`),
+        INDEX `hide_network_updated` (`hide`,`network`(4),`updated`),
         INDEX `updated` (`updated`)
 ) DEFAULT COLLATE utf8mb4_general_ci;
 
@@ -523,22 +536,22 @@ CREATE TABLE IF NOT EXISTS `item` (
         INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
         INDEX `uid_created` (`uid`,`created`),
         INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
-        INDEX `uid_network_received` (`uid`,`network`,`received`),
-        INDEX `uid_network_commented` (`uid`,`network`,`commented`),
-        INDEX `uid_thrparent` (`uid`,`thr-parent`),
-        INDEX `uid_parenturi` (`uid`,`parent-uri`),
+        INDEX `uid_network_received` (`uid`,`network`(4),`received`),
+        INDEX `uid_network_commented` (`uid`,`network`(4),`commented`),
+        INDEX `uid_thrparent` (`uid`,`thr-parent`(190)),
+        INDEX `uid_parenturi` (`uid`,`parent-uri`(190)),
         INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
         INDEX `authorid_created` (`author-id`,`created`),
-        INDEX `uid_uri` (`uid`,`uri`),
+        INDEX `uid_uri` (`uid`,`uri`(190)),
         INDEX `resource-id` (`resource-id`),
         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`),
+        INDEX `uid_type_changed` (`uid`,`type`(190),`changed`),
+        INDEX `contactid_verb` (`contact-id`,`verb`(190)),
         INDEX `deleted_changed` (`deleted`,`changed`),
         INDEX `uid_wall_changed` (`uid`,`wall`,`changed`),
         INDEX `uid_eventid` (`uid`,`event-id`),
-        INDEX `uid_authorlink` (`uid`,`author-link`),
-        INDEX `uid_ownerlink` (`uid`,`owner-link`)
+        INDEX `uid_authorlink` (`uid`,`author-link`(190)),
+        INDEX `uid_ownerlink` (`uid`,`owner-link`(190))
 ) DEFAULT COLLATE utf8mb4_general_ci;
 
 --
@@ -652,7 +665,7 @@ CREATE TABLE IF NOT EXISTS `notify` (
         INDEX `hash_uid` (`hash`,`uid`),
         INDEX `seen_uid_date` (`seen`,`uid`,`date`),
         INDEX `uid_date` (`uid`,`date`),
-        INDEX `uid_type_link` (`uid`,`type`,`link`)
+        INDEX `uid_type_link` (`uid`,`type`,`link`(190))
 ) DEFAULT COLLATE utf8mb4_general_ci;
 
 --
@@ -963,7 +976,7 @@ CREATE TABLE IF NOT EXISTS `term` (
        `aid` int(10) unsigned NOT NULL DEFAULT 0,
        `uid` int(10) unsigned NOT NULL DEFAULT 0,
         PRIMARY KEY(`tid`),
-        INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`),
+        INDEX `oid_otype_type_term` (`oid`,`otype`,`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))
index 76791911a3c06fb3eec0332c4f333abcd1be5896..5846d49484d54a9c228e448354a6e0ddd1cf2bd1 100644 (file)
@@ -492,6 +492,9 @@ class dba {
                        $sql = "/*".$a->callstack()." */ ".$sql;
                }
 
+               self::$dbo->error = '';
+               self::$dbo->errorno = 0;
+
                switch (self::$dbo->driver) {
                        case 'pdo':
                                if (!$stmt = self::$dbo->db->prepare($sql)) {
@@ -563,6 +566,10 @@ class dba {
                                break;
                }
 
+               if (self::$dbo->errorno != 0) {
+                       logger('DB Error '.self::$dbo->errorno.': '.self::$dbo->error);
+               }
+
                $a->save_timestamp($stamp1, 'database');
 
                if (x($a->config,'system') && x($a->config['system'], 'db_log')) {
@@ -700,6 +707,23 @@ class dba {
                }
        }
 
+       /**
+        * @brief Insert a row into a table
+        *
+        * @param string $table Table name
+        * @param array $param parameter array
+        *
+        * @return boolean was the insert successfull?
+        */
+       static public function insert($table, $param) {
+               $sql = "INSERT INTO `".$table."` (`".implode("`, `", array_keys($param))."`) VALUES (".
+                       substr(str_repeat("?, ", count($param)), 0, -2).");";
+
+               $sql = self::replace_parameters($sql, $param);
+
+               return self::e($sql);
+       }
+
        /**
         * @brief Closes the current statement
         *
index a9d364a155ed30fb717a190c5dced37c74cb0ff1..5260a87a330f48c30efec0fb0d992409566565f9 100644 (file)
@@ -816,6 +816,7 @@ function db_definition() {
                                        "conversation-uri" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
                                        "protocol" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
                                        "source" => array("type" => "mediumtext"),
+                                       "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
                                        ),
                        "indexes" => array(
                                        "PRIMARY" => array("item-uri"),
index 2500e08d54ad78c5407d3a9405b7bc6631ab324e..3bf0a001c6a06d5a438df5de3e3f04a7b2a3ecb0 100644 (file)
@@ -690,6 +690,42 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
        item_body_set_hashtags($arr);
 
        $arr['thr-parent'] = $arr['parent-uri'];
+
+       if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
+               $conversation = array('item-uri' => $arr['uri'], 'received' => dbm::date());
+               if (isset($arr['thr-parent'])) {
+                       if ($arr['thr-parent'] != $arr['uri']) {
+                               $conversation['reply-to-uri'] = $arr['thr-parent'];
+                       }
+               }
+               if (isset($arr['conversation-uri'])) {
+                       $conversation['conversation-uri'] = $arr['conversation-uri'];
+                       unset($arr['conversation-uri']);
+               }
+
+               if ($arr['network'] == NETWORK_DFRN) {
+                       $conversation['protocol'] = PROTOCOL_DFRN;
+               } elseif ($arr['network'] == NETWORK_DIASPORA) {
+                       $conversation['protocol'] = PROTOCOL_DIASPORA;
+               }
+
+               if (isset($arr['protocol'])) {
+                       $conversation['protocol'] = $arr['protocol'];
+                       unset($arr['protocol']);
+               }
+               if (isset($arr['object'])) {
+                       $conversation['source'] = $arr['object'];
+                       if (in_array($arr['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
+                               unset($arr['object']);
+                       }
+               }
+               if (isset($arr['source'])) {
+                       $conversation['source'] = $arr['source'];
+                       unset($arr['source']);
+               }
+               dba::insert('conversation', $conversation);
+       }
+
        if ($arr['parent-uri'] === $arr['uri']) {
                $parent_id = 0;
                $parent_deleted = 0;
index c1d730eb130c4980c263a302ddc231a020636679..54d67d66edaf432a239883336f24c6c51ac15e96 100644 (file)
@@ -312,8 +312,10 @@ class ostatus {
 
                if ($first_child == "feed") {
                        $entries = $xpath->query('/atom:feed/atom:entry');
+                       $header["protocol"] = PROTOCOL_OSTATUS_FEED;
                } else {
                        $entries = $xpath->query('/atom:entry');
+                       $header["protocol"] = PROTOCOL_OSTATUS_SALMON;
                }
                $conversation = "";
                $conversationlist = array();
@@ -370,7 +372,7 @@ class ostatus {
                        } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
                                $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
                        }
-                       $item["object"] = $xml;
+                       $item["source"] = $xml;
 
                        /// @TODO
                        /// Delete a message
@@ -1172,7 +1174,9 @@ class ostatus {
                                $arr["app"] = "OStatus";
 
 
-                       $arr["object"] = json_encode($single_conv);
+                       $arr["source"] = json_encode($single_conv);
+                       $arr["protocol"] = PROTOCOL_GS_CONVERSATION;
+
                        $arr["verb"] = $parent["verb"];
                        $arr["visible"] = $parent["visible"];
                        $arr["location"] = $single_conv->location->displayName;