]> git.mxchange.org Git - friendica.git/commitdiff
SQL improvements. New parameter for a maximum amount of comments per thread
authorMichael Vogel <icarus@dabo.de>
Sun, 8 Dec 2013 13:49:24 +0000 (14:49 +0100)
committerMichael Vogel <icarus@dabo.de>
Sun, 8 Dec 2013 13:49:24 +0000 (14:49 +0100)
include/items.php
mod/network.php
mod/regmod.php

index 58768414356e4e79766630370e54bfddcac20d8f..a1aad551f6d645ddc13d24fbdd7527557501399b 100755 (executable)
@@ -2108,11 +2108,20 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                        $datarray['type'] = 'activity';
                                        $datarray['gravity'] = GRAVITY_LIKE;
                                        // only one like or dislike per person
-                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr-parent` = '%s') limit 1",
+                                       // splitted into two queries for performance issues
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s') limit 1",
+                                               intval($datarray['uid']),
+                                               intval($datarray['contact-id']),
+                                               dbesc($datarray['verb']),
+                                               dbesc($parent_uri)
+                                       );
+                                       if($r && count($r))
+                                               continue;
+
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`thr-parent` = '%s') limit 1",
                                                intval($datarray['uid']),
                                                intval($datarray['contact-id']),
                                                dbesc($datarray['verb']),
-                                               dbesc($parent_uri),
                                                dbesc($parent_uri)
                                        );
                                        if($r && count($r))
@@ -3009,11 +3018,21 @@ function local_delivery($importer,$data) {
                                        $datarray['gravity'] = GRAVITY_LIKE;
                                        $datarray['last-child'] = 0;
                                        // only one like or dislike per person
-                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr-parent` = '%s' or `parent-uri` = '%s') and deleted = 0 limit 1",
+                                       // splitted into two queries for performance issues
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`parent-uri` = '%s') and deleted = 0 limit 1",
+                                               intval($datarray['uid']),
+                                               intval($datarray['contact-id']),
+                                               dbesc($datarray['verb']),
+                                               dbesc($datarray['parent-uri'])
+
+                                       );
+                                       if($r && count($r))
+                                               continue;
+
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr-parent` = '%s') and deleted = 0 limit 1",
                                                intval($datarray['uid']),
                                                intval($datarray['contact-id']),
                                                dbesc($datarray['verb']),
-                                               dbesc($datarray['parent-uri']),
                                                dbesc($datarray['parent-uri'])
 
                                        );
@@ -3181,11 +3200,20 @@ function local_delivery($importer,$data) {
                                        $datarray['type'] = 'activity';
                                        $datarray['gravity'] = GRAVITY_LIKE;
                                        // only one like or dislike per person
-                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr-parent` = '%s') limit 1",
+                                       // splitted into two queries for performance issues
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s') limit 1",
+                                               intval($datarray['uid']),
+                                               intval($datarray['contact-id']),
+                                               dbesc($datarray['verb']),
+                                               dbesc($parent_uri)
+                                       );
+                                       if($r && count($r))
+                                               continue;
+
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`thr-parent` = '%s') limit 1",
                                                intval($datarray['uid']),
                                                intval($datarray['contact-id']),
                                                dbesc($datarray['verb']),
-                                               dbesc($parent_uri),
                                                dbesc($parent_uri)
                                        );
                                        if($r && count($r))
index f4f191d715282cbd96b6601609101ec4a4a2cf05..4c24943b07a908dc4ddb1ec6b0e0158da31db33c 100644 (file)
@@ -806,22 +806,36 @@ function network_content(&$a, $update = 0) {
                        foreach($r as $rr)
                                if(! in_array($rr['item_id'],$parents_arr))
                                        $parents_arr[] = $rr['item_id'];
-                       $parents_str = implode(', ', $parents_arr);
 
-                       $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
-                               `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
-                               `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
-                               `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
-                               FROM $sql_table 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`.`parent` IN ( %s )
-                               $sql_extra ",
-                               intval(local_user()),
-                               dbesc($parents_str)
-                       );
+                       //$parents_str = implode(', ', $parents_arr);
 
+                       // splitted into separate queries to avoid the problem with very long threads
+                       // so always the last X comments are loaded
+                       // This problem can occur expecially with imported facebook posts
+                       $max_comments = get_config("system", "max_comments");
+                       if ($max_comments == 0)
+                               $max_comments = 1000;
+
+                       $items = array();
+
+                       foreach ($parents_arr AS $parents_str) {
+
+                               $thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
+                                       `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
+                                       `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
+                                       `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
+                                       FROM $sql_table 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`.`parent` IN ( %s )
+                                       $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
+                                       intval(local_user()),
+                                       dbesc($parents_str),
+                                       intval($max_comments + 1)
+                               );
+                               $items = array_merge($items, $thread_items);
+                       }
                        $items = conv_sort($items,$ordering);
 
                } else {
index 5ed7642005628546069db335f818a55e97fe5971..96708eeaa4d521085cbee536a0d87e64477a6e94 100644 (file)
@@ -17,19 +17,19 @@ function user_allow($hash) {
        $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
                intval($register[0]['uid'])
        );
-       
+
        if(! count($user))
                killme();
 
-       $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
+       $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
                dbesc($register[0]['hash'])
        );
 
 
-       $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d LIMIT 1",
+       $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d",
                intval($register[0]['uid'])
        );
-       
+
        $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
                intval($user[0]['uid'])
        );
@@ -62,7 +62,7 @@ function user_allow($hash) {
        if($res) {
                info( t('Account approved.') . EOL );
                return true;
-       }       
+       }
 
 }
 
@@ -83,23 +83,23 @@ function user_deny($hash) {
        $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
                intval($register[0]['uid'])
        );
-       
-       $r = q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
+
+       $r = q("DELETE FROM `user` WHERE `uid` = %d",
                intval($register[0]['uid'])
        );
-       $r = q("DELETE FROM `contact` WHERE `uid` = %d LIMIT 1",
+       $r = q("DELETE FROM `contact` WHERE `uid` = %d",
                intval($register[0]['uid'])
-       ); 
-       $r = q("DELETE FROM `profile` WHERE `uid` = %d LIMIT 1",
+       );
+       $r = q("DELETE FROM `profile` WHERE `uid` = %d",
                intval($register[0]['uid'])
-       ); 
+       );
 
-       $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
+       $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
                dbesc($register[0]['hash'])
        );
        notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
        return true;
-       
+
 }
 
 function regmod_content(&$a) {