From d80a53abccc7e165a54d07e96cd556850f749ce5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 14 Mar 2018 11:50:53 -0700 Subject: [PATCH] Skip loading file transform sources when we know a file is not transformed Summary: Depends on D19223. Ref T13106. When we're loading a file, we currently test if it's a transformed version of another file (usually, a thumbnail) and apply policy behavior if it is. We know that builtins and profile images are never transforms and that the policy behavior for these files doesn't matter anyway. Skip loading transforms for these files. Test Plan: Saw local queries drop from 146 to 139 with no change in behavior. Maniphest Tasks: T13106 Differential Revision: https://secure.phabricator.com/D19224 --- .../files/query/PhabricatorFileQuery.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/applications/files/query/PhabricatorFileQuery.php b/src/applications/files/query/PhabricatorFileQuery.php index 83bf2d8dec..9f1659a7f3 100644 --- a/src/applications/files/query/PhabricatorFileQuery.php +++ b/src/applications/files/query/PhabricatorFileQuery.php @@ -165,6 +165,7 @@ final class PhabricatorFileQuery // However, in some special cases where we know files will always be // visible, we skip this. See T8478 and T13106. $need_objects = array(); + $need_xforms = array(); foreach ($files as $file) { $always_visible = false; @@ -187,6 +188,7 @@ final class PhabricatorFileQuery } $need_objects[] = $file; + $need_xforms[] = $file; } $viewer = $this->getViewer(); @@ -226,15 +228,20 @@ final class PhabricatorFileQuery // If this file is a transform of another file, load that file too. If you // can see the original file, you can see the thumbnail. - // TODO: It might be nice to put this directly on PhabricatorFile and remove - // the PhabricatorTransformedFile table, which would be a little simpler. + // TODO: It might be nice to put this directly on PhabricatorFile and + // remove the PhabricatorTransformedFile table, which would be a little + // simpler. - $xforms = id(new PhabricatorTransformedFile())->loadAllWhere( - 'transformedPHID IN (%Ls)', - mpull($files, 'getPHID')); - $xform_phids = mpull($xforms, 'getOriginalPHID', 'getTransformedPHID'); - foreach ($xform_phids as $derived_phid => $original_phid) { - $object_phids[$original_phid] = true; + if ($need_xforms) { + $xforms = id(new PhabricatorTransformedFile())->loadAllWhere( + 'transformedPHID IN (%Ls)', + mpull($need_xforms, 'getPHID')); + $xform_phids = mpull($xforms, 'getOriginalPHID', 'getTransformedPHID'); + foreach ($xform_phids as $derived_phid => $original_phid) { + $object_phids[$original_phid] = true; + } + } else { + $xform_phids = array(); } $object_phids = array_keys($object_phids);