From 0241a88c0df33ce4ed68fb5a017b386fb5c4cb8b Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 1 May 2017 19:54:08 +0000 Subject: [PATCH] Avoid duplicated queries --- include/dba.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/dba.php b/include/dba.php index 11e1d2131d..924c31e05f 100644 --- a/include/dba.php +++ b/include/dba.php @@ -785,7 +785,7 @@ class dba { * * @return boolean|array was the delete successfull? When $in_commit is set: deletion data */ - static public function delete($table, $param, $in_commit = false, $callstack = array()) { + static public function delete($table, $param, $in_commit = false, &$callstack = array()) { $commands = array(); @@ -797,7 +797,7 @@ class dba { return $commands; } - $callstack[$key] = $key; + $callstack[$key] = true; $table = self::$dbo->escape($table); @@ -824,6 +824,16 @@ class dba { } } } else { + // Create a key for preventing double queries + $qkey = $field.'-'.$table.':'.implode(':', array_keys($param)).':'.implode(':', $param); + + // We quit when this key already exists in the callstack. + if (isset($callstack[$qkey])) { + continue; + } + + $callstack[$qkey] = true; + // Fetch all rows that are to be deleted $sql = "SELECT ".self::$dbo->escape($field)." FROM `".$table."` WHERE `". implode("` = ? AND `", array_keys($param))."` = ?"; -- 2.39.5