]> git.mxchange.org Git - friendica.git/commitdiff
Small performance improvements
authorMichael Vogel <icarus@dabo.de>
Mon, 1 Aug 2016 05:22:54 +0000 (07:22 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 1 Aug 2016 05:22:54 +0000 (07:22 +0200)
include/acl_selectors.php
include/text.php

index 76f0e0b79609caf74d9c1a68bd11f0bea209b654..71a42478ba92c06b80c02f6f3d332af6382deba4 100644 (file)
@@ -481,11 +481,11 @@ function acl_lookup(&$a, $out_type = 'json') {
        if ($type=='' || $type=='g'){
 
                $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') AS uids
-                               FROM `group`,`group_member`
-                               WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
-                                       AND `group_member`.`gid`=`group`.`id`
+                               FROM `group`
+                               INNER JOIN `group_member` ON `group_member`.`gid`=`group`.`id` AND `group_member`.`uid` = `group`.`uid`
+                               WHERE NOT `group`.`deleted` AND `group`.`uid` = %d
                                        $sql_extra
-                               GROUP BY `group`.`id`
+                               GROUP BY `group`.`name`
                                ORDER BY `group`.`name`
                                LIMIT %d,%d",
                        intval(local_user()),
index 2da9a180ea1ef30d0bd9fcac84dac396ffff78ed..3aec42b3239b1fbee986d15b60183f53f05fc9fa 100644 (file)
@@ -872,7 +872,8 @@ function contact_block() {
                $micropro = Null;
 
        } else {
-               $r = q("SELECT `id`, `uid`, `addr`, `url`, `name`, `thumb`, `network` FROM `contact`
+               // Splitting the query in two parts makes it much faster
+               $r = q("SELECT `id` FROM `contact`
                                WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending`
                                        AND NOT `hidden` AND NOT `archive`
                                AND `network` IN ('%s', '%s', '%s') ORDER BY RAND() LIMIT %d",
@@ -882,11 +883,19 @@ function contact_block() {
                                dbesc(NETWORK_DIASPORA),
                                intval($shown)
                );
-               if(count($r)) {
-                       $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total);
-                       $micropro = Array();
-                       foreach($r as $rr) {
-                               $micropro[] = micropro($rr,true,'mpfriend');
+               if ($r) {
+                       $contacts = "";
+                       foreach ($r AS $contact)
+                               $contacts[] = $contact["id"];
+
+                       $r = q("SELECT `id`, `uid`, `addr`, `url`, `name`, `thumb`, `network` FROM `contact` WHERE `id` IN (%s)",
+                               dbesc(implode(",", $contacts)));
+                       if(count($r)) {
+                               $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total);
+                               $micropro = Array();
+                               foreach($r as $rr) {
+                                       $micropro[] = micropro($rr,true,'mpfriend');
+                               }
                        }
                }
        }