]> git.mxchange.org Git - friendica.git/commitdiff
Optimized queries
authorMichael Vogel <icarus@dabo.de>
Mon, 18 Jul 2016 13:25:42 +0000 (15:25 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 18 Jul 2016 13:25:42 +0000 (15:25 +0200)
include/api.php
include/xml.php

index 4796228f9d77c6188d5e976de3e9b69ad192db72..ff2d083cc891ccd89aba8efac48f8cf33748e83d 100644 (file)
                                        'notifications' => false,
                                        'statusnet_profile_url' => $r[0]["url"],
                                        'uid' => 0,
-                                       'cid' => 0,
+                                       'cid' => get_contact($r[0]["url"], api_user()),
                                        'self' => 0,
                                        'network' => $r[0]["network"],
                                );
                $user_info = api_get_user($a);
 
                $lastwall = q("SELECT `item`.*
-                               FROM `item`, `contact`
+                               FROM `item`
+                               INNER JOIN `contact` ON `contact`.`id`=`item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
                                WHERE `item`.`uid` = %d AND `verb` = '%s' AND `item`.`contact-id` = %d
                                        AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
-                                       AND `contact`.`id`=`item`.`contact-id`
                                        AND `type`!='activity'
                                        AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
                                ORDER BY `created` DESC
                                dbesc($user_info['url']),
                                dbesc(normalise_link($user_info['url']))
                );
+
                if (count($lastwall)>0){
                        $lastwall = $lastwall[0];
 
                if ($conversation_id > 0)
                        $sql_extra .= ' AND `item`.`parent` = '.intval($conversation_id);
 
-               $r = q("SELECT STRAIGHT_JOIN `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
+               $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
                        `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
                        `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
                        `contact`.`id` AS `cid`
-                       FROM `item`, `contact`
+                       FROM `item`
+                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
+                               AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
                        WHERE `item`.`uid` = %d AND `verb` = '%s'
-                       AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
-                       AND `contact`.`id` = `item`.`contact-id`
-                       AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
+                       AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
                        $sql_extra
                        AND `item`.`id`>%d
                        ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
                        `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
                        `contact`.`id` AS `cid`,
                        `user`.`nickname`, `user`.`hidewall`
-                       FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
+                       FROM `item`
+                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
+                               AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
                        STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
-                       WHERE `verb` = '%s' AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
+                               AND NOT `user`.`hidewall`
+                       WHERE `verb` = '%s' AND `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
                        AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
                        AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
-                       AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0
-                       AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
+                       AND NOT `item`.`private` AND `item`.`wall`
                        $sql_extra
                        AND `item`.`id`>%d
                        ORDER BY `item`.`id` DESC LIMIT %d, %d ",
                        `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
                        `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
                        `contact`.`id` AS `cid`
-                       FROM `item`, `contact`
-                       WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
-                       AND `contact`.`id` = `item`.`contact-id` AND `item`.`uid` = %d AND `item`.`verb` = '%s'
-                       AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
+                       FROM `item`
+                       INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
+                               AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
+                       WHERE `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
+                       AND `item`.`uid` = %d AND `item`.`verb` = '%s'
                        $sql_extra",
                        intval(api_user()),
                        dbesc(ACTIVITY_POST),
                        `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
                        `contact`.`id` AS `cid`
                        FROM `item`
-                       INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
+                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
+                               AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
                        WHERE `item`.`parent` = %d AND `item`.`visible`
                        AND NOT `item`.`moderated` AND NOT `item`.`deleted`
                        AND `item`.`uid` = %d AND `item`.`verb` = '%s'
-                       AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
                        AND `item`.`id`>%d $sql_extra
                        ORDER BY `item`.`id` DESC LIMIT %d ,%d",
                        intval($id), intval(api_user()),
                        `contact`.`name`, `contact`.`photo` as `reply_photo`, `contact`.`url` as `reply_url`, `contact`.`rel`,
                        `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
                        `contact`.`id` AS `cid`
-                       FROM `item`, `contact`
-                       WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
-                       AND `contact`.`id` = `item`.`contact-id`
-                       AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
+                       FROM `item`
+                       INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
+                               AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
+                       WHERE `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
                        AND NOT `item`.`private` AND `item`.`allow_cid` = '' AND `item`.`allow`.`gid` = ''
                        AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
                        $sql_extra
                        `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
                        `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
                        `contact`.`id` AS `cid`
-                       FROM `item`  FORCE INDEX (`uid_id`), `contact`
+                       FROM `item` FORCE INDEX (`uid_id`)
+                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
+                               AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
                        WHERE `item`.`uid` = %d AND `verb` = '%s'
                        AND NOT (`item`.`author-link` IN ('https://%s', 'http://%s'))
                        AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
-                       AND `contact`.`id` = `item`.`contact-id`
-                       AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
                        AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `uid` = %d AND `mention` AND !`ignored`)
                        $sql_extra
                        AND `item`.`id`>%d
                        `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
                        `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
                        `contact`.`id` AS `cid`
-                       FROM `item`
-                       INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
+                       FROM `item` FORCE INDEX (`uid_contactid_id`)
+                       STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
                                AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
                        WHERE `item`.`uid` = %d AND `verb` = '%s'
                        AND `item`.`contact-id` = %d
index d2a0f7655bf2af66d7fc2e86297868e0df3aad8d..a60d0671d31f6476eb90fe3d09247b85cb816db1 100644 (file)
@@ -64,8 +64,6 @@ class xml {
                                        $element_parts = explode(":", $attr_key);
                                        if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
                                                $namespace = $namespaces[$element_parts[0]];
-                                       elseif (isset($namespaces[""]))
-                                               $namespace = $namespaces[""];
                                        else
                                                $namespace = NULL;