]> git.mxchange.org Git - friendica.git/commitdiff
Delete queries are now split into chunks.
authorMichael <heluecht@pirati.ca>
Mon, 1 May 2017 17:42:37 +0000 (17:42 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 1 May 2017 17:42:37 +0000 (17:42 +0000)
boot.php
include/dba.php
include/dbstructure.php
update.php

index 99af7d3778c1012e3312647deac47eaf63388224..b689b73eece112a87558b304745ff806569ac605 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
 define ( 'FRIENDICA_VERSION',      '3.5.2-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1221      );
+define ( 'DB_UPDATE_VERSION',      1222      );
 
 /**
  * @brief Constant with a HTML line break.
index dfba269bf4ecb57201f46959d973cd7b4b0bf4f2..11e1d2131d27f74a9d5c0ebf5057c79e0858a3e8 100644 (file)
@@ -768,7 +768,7 @@ class dba {
                        foreach ($structure['fields'] AS $field => $field_struct) {
                                if (isset($field_struct['relation'])) {
                                        foreach ($field_struct['relation'] AS $rel_table => $rel_field) {
-                                               self::$relation[$rel_table][$rel_field][$table] = $field;
+                                               self::$relation[$rel_table][$rel_field][$table][] = $field;
                                        }
                                }
                        }
@@ -817,15 +817,17 @@ class dba {
                        // When the search field is the relation field, we don't need to fetch the rows
                        // This is useful when the leading record is already deleted in the frontend but the rest is done in the backend
                        if ((count($param) == 1) AND ($field == array_keys($param)[0])) {
-                               foreach ($rel_def AS $rel_table => $rel_field) {
-                                       $retval = self::delete($rel_table, array($rel_field => array_values($param)[0]), true, $callstack);
-                                       $commands = array_merge($commands, $retval);
+                               foreach ($rel_def AS $rel_table => $rel_fields) {
+                                       foreach ($rel_fields AS $rel_field) {
+                                               $retval = self::delete($rel_table, array($rel_field => array_values($param)[0]), true, $callstack);
+                                               $commands = array_merge($commands, $retval);
+                                       }
                                }
                        } else {
                                // Fetch all rows that are to be deleted
                                $sql = "SELECT ".self::$dbo->escape($field)." FROM `".$table."` WHERE `".
                                implode("` = ? AND `", array_keys($param))."` = ?";
-                               $retval = false;
+
                                $data = self::p($sql, $param);
                                while ($row = self::fetch($data)) {
                                        // Now we accumulate the delete commands
@@ -833,10 +835,6 @@ class dba {
                                        $commands = array_merge($commands, $retval);
                                }
 
-                               // When we don't find data then we don't need to delete it
-                               if (is_bool($retval)) {
-                                       return $in_commit ? $commands : true;
-                               }
                                // Since we had split the delete command we don't need the original command anymore
                                unset($commands[$key]);
                        }
@@ -848,6 +846,7 @@ class dba {
                        self::p("START TRANSACTION");
 
                        $compacted = array();
+                       $counter = array();
                        foreach ($commands AS $command) {
                                if (count($command['param']) > 1) {
                                        $sql = "DELETE FROM `".$command['table']."` WHERE `".
@@ -860,20 +859,33 @@ class dba {
                                                return false;
                                        }
                                } else {
+                                       $key_table = $command['table'];
+                                       $key_param = array_keys($command['param'])[0];
                                        $value = array_values($command['param'])[0];
-                                       $compacted[$command['table']][array_keys($command['param'])[0]][$value] = $value;
+
+                                       // Split the SQL queries in chunks of 100 values
+                                       // We do the $i stuff here to make the code better readable
+                                       $i = $counter[$key_table][$key_param];
+                                       if (count($compacted[$key_table][$key_param][$i]) > 100) {
+                                               ++$i;
+                                       }
+
+                                       $compacted[$key_table][$key_param][$i][$value] = $value;
+                                       $counter[$key_table][$key_param] = $i;
                                }
                        }
                        foreach ($compacted AS $table => $values) {
-                               foreach ($values AS $field => $field_values) {
-                                       $sql = "DELETE FROM `".$table."` WHERE `".$field."` IN (".
-                                       substr(str_repeat("?, ", count($field_values)), 0, -2).");";
+                               foreach ($values AS $field => $field_value_list) {
+                                       foreach ($field_value_list AS $field_values) {
+                                               $sql = "DELETE FROM `".$table."` WHERE `".$field."` IN (".
+                                                       substr(str_repeat("?, ", count($field_values)), 0, -2).");";
 
-                                       logger(dba::replace_parameters($sql, $field_values), LOGGER_DATA);
+                                               logger(dba::replace_parameters($sql, $field_values), LOGGER_DATA);
 
-                                       if (!self::e($sql, $param)) {
-                                               self::p("ROLLBACK");
-                                               return false;
+                                               if (!self::e($sql, $param)) {
+                                                       self::p("ROLLBACK");
+                                                       return false;
+                                               }
                                        }
                                }
                        }
index 25109b5f4008fdae121d6f6db806c88470b6a540..06e81e495843b1bb5c7439eead1c4a13ba067f30 100644 (file)
@@ -1152,6 +1152,7 @@ function db_definition() {
                                        "uid_parenturi" => array("uid","parent-uri(190)"),
                                        "uid_contactid_created" => array("uid","contact-id","created"),
                                        "authorid_created" => array("author-id","created"),
+                                       "ownerid" => array("owner-id"),
                                        "uid_uri" => array("uid", "uri(190)"),
                                        "resource-id" => array("resource-id"),
                                        "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), //
@@ -1627,6 +1628,9 @@ function db_definition() {
                                        "uid_network_created" => array("uid","network","created"),
                                        "uid_contactid_commented" => array("uid","contact-id","commented"),
                                        "uid_contactid_created" => array("uid","contact-id","created"),
+                                       "contactid" => array("contact-id"),
+                                       "ownerid" => array("owner-id"),
+                                       "authorid" => array("author-id"),
                                        "uid_created" => array("uid","created"),
                                        "uid_commented" => array("uid","commented"),
                                        "uid_wall_created" => array("uid","wall","created"),
index 704f2ac0614e344304c6eb256e879ebab78d5ef6..bdb3d68839e9a66b199aa53179245c052b1a0d01 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define('UPDATE_VERSION' , 1221);
+define('UPDATE_VERSION' , 1222);
 
 /**
  *