]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'upstream/develop' into 1607-performance
authorMichael <heluecht@pirati.ca>
Wed, 16 Nov 2016 06:27:21 +0000 (06:27 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 16 Nov 2016 06:27:21 +0000 (06:27 +0000)
Conflicts:
include/dbstructure.php
mod/item.php
mod/nodeinfo.php

include/Contact.php
include/dba.php
include/dbstructure.php
include/onepoll.php
mod/contacts.php
mod/follow.php
mod/network.php
mod/nodeinfo.php

index 23b5bbe5b82be3d8207c9dbf87f70c240736b5f3..05e5dc62fcf84a957f5dde7a571330ae89bad951 100644 (file)
@@ -652,57 +652,64 @@ function posts_from_gcontact($a, $gcontact_id) {
 
        return $o;
 }
-
 /**
- * @brief Returns posts from a given contact
+ * @brief Returns posts from a given contact url
  *
  * @param App $a argv application class
- * @param int $contact_id contact
+ * @param int $contact_url Contact URL
  *
  * @return string posts in HTML
  */
-function posts_from_contact($a, $contact_id) {
+function posts_from_contact_url($a, $contact_url) {
 
        require_once('include/conversation.php');
 
-       $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
-       if (!$r)
-               return false;
+       // There are no posts with "uid = 0" with connector networks
+       // This speeds up the query a lot
+       $r = q("SELECT `network`, `id` AS `author-id` FROM `contact`
+               WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0",
+               dbesc(normalise_link($contact_url)));
+       if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, "")))
+               $sql = "(`item`.`uid` = 0 OR  (`item`.`uid` = %d AND `item`.`private`))";
+       else
+               $sql = "`item`.`uid` = %d";
 
-       $contact = $r[0];
+       $author_id = intval($r[0]["author-id"]);
 
-       if(get_config('system', 'old_pager')) {
+       if (get_config('system', 'old_pager')) {
                $r = q("SELECT COUNT(*) AS `total` FROM `item`
-                       WHERE `item`.`uid` = %d AND `author-link` IN ('%s', '%s')",
-                       intval(local_user()),
-                       dbesc(str_replace("https://", "http://", $contact["url"])),
-                       dbesc(str_replace("http://", "https://", $contact["url"])));
+                       WHERE `author-id` = %d and $sql",
+                       intval($author_id),
+                       intval(local_user()));
 
                $a->set_pager_total($r[0]['total']);
        }
 
-       $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
+/*
+"SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
                        `author-name` AS `name`, `owner-avatar` AS `photo`,
                        `owner-link` AS `url`, `owner-avatar` AS `thumb`
-               FROM `item` FORCE INDEX (`uid_contactid_id`)
-               WHERE `item`.`uid` = %d AND `contact-id` = %d
-                       AND `author-link` IN ('%s', '%s')
-                       AND NOT `deleted` AND NOT `moderated` AND `visible`
-               ORDER BY `item`.`id` DESC LIMIT %d, %d",
+               FROM `item` FORCE INDEX (`authorid_created`)
+               WHERE `item`.`author-id` = %d AND $sql
+               AND NOT `deleted` AND NOT `moderated` AND `visible`
+
+*/
+
+       $r = q(item_query()." AND `item`.`author-id` = %d AND ".$sql.
+               " ORDER BY `item`.`created` DESC LIMIT %d, %d",
+               intval($author_id),
                intval(local_user()),
-               intval($contact_id),
-               dbesc(str_replace("https://", "http://", $contact["url"])),
-               dbesc(str_replace("http://", "https://", $contact["url"])),
                intval($a->pager['start']),
                intval($a->pager['itemspage'])
        );
 
-       $o .= conversation($a,$r,'community',false);
+       $o = conversation($a,$r,'community',false);
 
-       if(!get_config('system', 'old_pager'))
+       if(!get_config('system', 'old_pager')) {
                $o .= alt_pager($a,count($r));
-       else
+       } else {
                $o .= paginate($a);
+       }
 
        return $o;
 }
index 082a54bd496694875cb7756974f049c2f065a179..7ca520712a455a31d53d4b92e24800cbcbdac124 100644 (file)
@@ -65,6 +65,7 @@ class dba {
                        $this->db = @new mysqli($server,$user,$pass,$db);
                        if (! mysqli_connect_errno()) {
                                $this->connected = true;
+                               //mysqli_set_charset($this->db, 'utf8');
                        }
                        if (isset($a->config["system"]["db_charset"])) {
                                $this->db->set_charset($a->config["system"]["db_charset"]);
@@ -74,6 +75,7 @@ class dba {
                        $this->db = mysql_connect($server,$user,$pass);
                        if ($this->db && mysql_select_db($db,$this->db)) {
                                $this->connected = true;
+                               //mysql_set_charset('utf8', $this->db);
                        }
                        if (isset($a->config["system"]["db_charset"]))
                                mysql_set_charset($a->config["system"]["db_charset"], $this->db);
index bd4a07eb56e73a9c63bb4cb468409da66d62ebfc..a76e3e2723211d7fa40d8a5d4b0074e37428b727 100644 (file)
@@ -905,20 +905,20 @@ function db_definition($charset) {
                                        "uid_created" => array("uid","created"),
                                        "uid_unseen_contactid" => array("uid","unseen","contact-id"),
                                        "uid_network_received" => array("uid","network","received"),
-                                       "uid_received" => array("uid","received"),
-                                       "uid_network_commented" => array("uid","network","commented"),
-                                       "uid_commented" => array("uid","commented"),
+                                       //"uid_received" => array("uid","received"),
+                                       //"uid_network_commented" => array("uid","network","commented"),
+                                       //"uid_commented" => array("uid","commented"),
                                        "uid_title" => array("uid","title"),
                                        "uid_thrparent" => array("uid","thr-parent"),
                                        "uid_parenturi" => array("uid","parent-uri"),
                                        "uid_contactid_id" => array("uid","contact-id","id"),
-                                       "uid_contactid_created" => array("uid","contact-id","created"),
+                                       //"uid_contactid_created" => array("uid","contact-id","created"),
                                        "gcontactid_uid_created" => array("gcontact-id","uid","created"),
                                        "authorid_created" => array("author-id","created"),
                                        "ownerid_created" => array("owner-id","created"),
-                                       "wall_body" => array("wall","body(6)"),
-                                       "uid_visible_moderated_created" => array("uid","visible","moderated","created"),
-                                       "uid_uri" => array("uid", "uri"),
+                                       //"wall_body" => array("wall","body(6)"),
+                                       //"uid_visible_moderated_created" => array("uid","visible","moderated","created"),
+                                       "uid_uri" => array("uid","uri"),
                                        "uid_wall_created" => array("uid","wall","created"),
                                        "resource-id" => array("resource-id"),
                                        "uid_type" => array("uid","type"),
@@ -926,7 +926,8 @@ function db_definition($charset) {
                                        "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"),
                                        "uid_wall_parent_created" => array("uid","wall","parent","created"),
                                        "uid_type_changed" => array("uid","type","changed"),
-                                       "contactid_verb" => array("contact-id","verb"),
+                                       //"contactid_verb" => array("contact-id","verb"),
+                                       "contactid" => array("contact-id"),
                                        "deleted_changed" => array("deleted","changed"),
                                        "uid_wall_changed" => array("uid","wall","changed"),
                                        "uid_eventid" => array("uid","event-id"),
index 951b87043e06d8a014f81ad365eb62d8b5abfdc3..4ac5f38bee43e919a9901104f0ae64b7a2020086 100644 (file)
@@ -475,9 +475,10 @@ function onepoll_run(&$argv, &$argc){
 
                                                // If it seems to be a reply but a header couldn't be found take the last message with matching subject
                                                if(!x($datarray,'parent-uri') and $reply) {
-                                                       $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d ORDER BY `created` DESC LIMIT 1",
+                                                       $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d AND `network` = '%s' ORDER BY `created` DESC LIMIT 1",
                                                                dbesc(protect_sprintf($datarray['title'])),
-                                                               intval($importer_uid));
+                                                               intval($importer_uid),
+                                                               dbesc(NETWORK_MAIL));
                                                        if(count($r))
                                                                $datarray['parent-uri'] = $r[0]['parent-uri'];
                                                }
index 23907669a6a91994f389da881a9afdec73ee7237..1c1c21638d4e2225254debf94d02874ad6845a3f 100644 (file)
@@ -894,16 +894,7 @@ function contact_posts($a, $contact_id) {
 
        $o .= $tab_str;
 
-       $r = q("SELECT `id` FROM `item` WHERE `contact-id` = %d LIMIT 1", intval($contact_id));
-       if ($r)
-               $o .= posts_from_contact($a, $contact_id);
-       elseif ($contact["url"]) {
-               $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
-                       dbesc(normalise_link($contact["url"])));
-
-               if ($r[0]["id"] <> 0)
-                       $o .= posts_from_gcontact($a, $r[0]["id"]);
-       }
+       $o .= posts_from_contact_url($a, $contact["url"]);
 
        return $o;
 }
index b92a0d980fb57e1150214c07aee7e5b590277c05..1f56caea5094451ecf1add9ec80d10b0373b9110 100644 (file)
@@ -137,13 +137,13 @@ function follow_content(&$a) {
        $a->page['aside'] = "";
        profile_load($a, "", 0, get_contact_details_by_url($ret["url"]));
 
-       // Show last public posts
        if ($gcontact_id <> 0) {
                $o .= replace_macros(get_markup_template('section_title.tpl'),
                                                array('$title' => t('Status Messages and Posts')
                ));
 
-               $o .= posts_from_gcontact($a, $gcontact_id);
+               // Show last public posts
+               $o .= posts_from_contact_url($a, $ret["url"]);
        }
 
        return $o;
index 559bad0a3e332208c6795898135007f7674ced82..1b7574d1097c99211be99399b14940dc615f2806 100644 (file)
@@ -578,8 +578,8 @@ function network_content(&$a, $update = 0) {
                                $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
                        else
                                $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
-                       $sql_order = "`item`.`received`";
-                       $order_mode = "received";
+                       $sql_order = "`item`.`id`";
+                       $order_mode = "id";
                }
        }
        if(strlen($file)) {
@@ -597,8 +597,7 @@ function network_content(&$a, $update = 0) {
                // only setup pagination on initial page view
                $pager_sql = '';
 
-       }
-       else {
+       } else {
                if(get_config('system', 'old_pager')) {
                        $r = qu("SELECT COUNT(*) AS `total`
                                FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = $sql_table.`contact-id`
@@ -637,7 +636,7 @@ function network_content(&$a, $update = 0) {
                $simple_update = (($update) ? " AND `item`.`unseen` " : '');
 
                if ($sql_order == "")
-                       $sql_order = "`item`.`received`";
+                       $sql_order = "`item`.`id`";
 
                // "New Item View" - show all items unthreaded in reverse created date order
                $items = qu("SELECT %s FROM $sql_table $sql_post_table %s
index 40094ee6e3a24047c572d479af1624a97adcd9ac..334dcb055d6c3868c43016e6c864d60ef3ce2222 100644 (file)
@@ -174,7 +174,7 @@ function nodeinfo_cron() {
                return;
 
        $last = get_config('nodeinfo','last_calucation');
-
+/*
        if($last) {
                // Calculate every 24 hours
                $next = $last + (24 * 60 * 60);
@@ -183,7 +183,7 @@ function nodeinfo_cron() {
                        return;
                }
        }
-        logger("cron_start");
+*/        logger("cron_start");
 
        $users = qu("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
                        FROM `user`
@@ -217,11 +217,13 @@ function nodeinfo_cron() {
                        set_config('nodeinfo','active_users_monthly', $active_users_monthly);
        }
 
+       $posts = qu("SELECT COUNT(*) AS local_posts FROM `thread` WHERE `thread`.`wall`");
+/*
        $posts = qu("SELECT COUNT(*) AS `local_posts` FROM `item`
                        INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                        WHERE `contact`.`self` and `item`.`id` = `item`.`parent` AND left(body, 6) != '[share' AND `item`.`network` IN ('%s', '%s', '%s')",
                        dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
-
+*/
        if (!is_array($posts))
                $local_posts = -1;
        else