]> git.mxchange.org Git - friendica.git/commitdiff
Speed improvements of queries
authorMichael Vogel <icarus@dabo.de>
Sat, 5 Oct 2013 10:30:10 +0000 (12:30 +0200)
committerMichael Vogel <icarus@dabo.de>
Sat, 5 Oct 2013 10:30:10 +0000 (12:30 +0200)
include/api.php
mod/community.php
mod/profile.php

index 5e80e0f0a317c54020177d021e4250c4d028e164..cfbf7a7e5c78eedb47977ef8c75ce84c3fc998b9 100644 (file)
        function api_status_show(&$a, $type){
                $user_info = api_get_user($a);
                // get last public wall message
-               $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
-                               FROM `item`, `contact`,
-                                       (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i` 
+
+               $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `c`.`nick` as `reply_author`
+                               FROM `item`, `contact`, `item` as `i`, `contact` as `c`
                                WHERE `item`.`contact-id` = %d
                                        AND `i`.`id` = `item`.`parent`
-                                       AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
-                                       AND `type`!='activity'
+                                       AND `contact`.`id`=`item`.`contact-id` AND `c`.`id`=`i`.`contact-id` AND `contact`.`self`=1
+                                       AND `item`.`type`!='activity'
                                        AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
-                               ORDER BY `created` DESC 
+                               ORDER BY `item`.`created` DESC
                                LIMIT 1",
                                intval($user_info['id'])
                );
 
+//             $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
+//                             FROM `item`, `contact`,
+//                                     (SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i` 
+//                             WHERE `item`.`contact-id` = %d
+//                                     AND `i`.`id` = `item`.`parent`
+//                                     AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
+//                                     AND `type`!='activity'
+//                                     AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
+//                             ORDER BY `created` DESC
+//                             LIMIT 1",
+//                             intval($user_info['id'])
+//             );
+
                if (count($lastwall)>0){
                        $lastwall = $lastwall[0];
 
index 1f8adf89072ba1fd17d538279f3416967734ee66..dbf4c82beb8eb4a581e2757394830d4093017a71 100644 (file)
@@ -70,7 +70,7 @@ function community_content(&$a, $update = 0) {
                `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
                `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
                `user`.`nickname`, `user`.`hidewall`
-               FROM `item` FORCE INDEX (`received`) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
+               FROM `item` FORCE INDEX (`received`, `wall`) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
                WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
                AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
index c5f787a4f0792fd33a636a18dffd1be13d1153f9..c5da0ebed3689f7be1292f639f3ba9996555e478 100644 (file)
@@ -277,7 +277,7 @@ function profile_content(&$a, $update = 0) {
                $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
 
                $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
-                       FROM `item` FORCE INDEX (created) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
+                       FROM `item` FORCE INDEX (created, uid) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                        WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
                        and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                        AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1