From c9da36d73194ab1da0e807a6977da054fa6261ba Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Wed, 10 Aug 2022 15:09:20 +0800 Subject: [PATCH] MDL-74910 core_files: Return SQL to initial state MDL-73727 aimed to improve the performance of the get_conversions_for_file SQL. Unfortunately it also changed the behvaiour of the SQL. On further investigation, there is nothing wrong with the SQL. This patch returns it back to its initial state. --- files/classes/conversion.php | 37 +++++++----------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/files/classes/conversion.php b/files/classes/conversion.php index 0a2e8610ed56d..f0a181900477f 100644 --- a/files/classes/conversion.php +++ b/files/classes/conversion.php @@ -128,36 +128,13 @@ public static function get_conversions_for_file(stored_file $file, $format) { // Fetch actual conversions which relate to the specified source file, and have a matching conversion record, // and either have a valid destination file which still exists, or do not have a destination file at all. - $dbfamily = $DB->get_dbfamily(); - switch ($dbfamily) { - // For certain DB engines, use a more optimised query. - case 'mysql': - case 'postgres': - $sql = "SELECT {$sqlfields} - FROM {" . self::TABLE . "} c - JOIN (SELECT id - FROM {files} - WHERE contenthash = :ccontenthash - LIMIT 1 - ) conversionsourcefile ON conversionsourcefile.id = c.sourcefileid - LEFT JOIN {files} conversiondestfile ON conversiondestfile.id = c.destfileid - WHERE c.targetformat = :cformat - AND (c.destfileid IS NULL - OR conversiondestfile.id IS NOT NULL)"; - break; - - // For everything else, use the standard cross-db compatible query. - default: - $sql = "SELECT {$sqlfields} - FROM {" . self::TABLE . "} c - INNER JOIN {files} conversionsourcefile ON conversionsourcefile.id = c.sourcefileid - LEFT JOIN {files} conversiondestfile ON conversiondestfile.id = c.destfileid - WHERE conversionsourcefile.contenthash = :ccontenthash - AND c.targetformat = :cformat - AND (c.destfileid IS NULL - OR conversiondestfile.id IS NOT NULL)"; - break; - } + $sql = "SELECT {$sqlfields} + FROM {" . self::TABLE . "} c + JOIN {files} conversionsourcefile ON conversionsourcefile.id = c.sourcefileid + LEFT JOIN {files} conversiondestfile ON conversiondestfile.id = c.destfileid + WHERE conversionsourcefile.contenthash = :ccontenthash + AND c.targetformat = :cformat + AND (c.destfileid IS NULL OR conversiondestfile.id IS NOT NULL)"; // Fetch a empty conversion record for each source/destination combination that we find to match where the // destination file is in the correct filearea/filepath/filename combination to meet the requirements.