Skip to content

Commit

Permalink
MDL-74910 core_files: Return SQL to initial state
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cameron1729 authored and junpataleta committed Oct 20, 2022
1 parent d9632ca commit c9da36d
Showing 1 changed file with 7 additions and 30 deletions.
37 changes: 7 additions & 30 deletions files/classes/conversion.php
Expand Up @@ -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.
Expand Down

0 comments on commit c9da36d

Please sign in to comment.