Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/query/PhabricatorFileQuery.php
| Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | final class PhabricatorFileQuery | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| $files = $this->loadStandardPage(new PhabricatorFile()); | $files = $this->loadStandardPage(new PhabricatorFile()); | ||||
| if (!$files) { | if (!$files) { | ||||
| return $files; | return $files; | ||||
| } | } | ||||
| $viewer = $this->getViewer(); | |||||
| $is_omnipotent = $viewer->isOmnipotent(); | |||||
| // We need to load attached objects to perform policy checks for files. | // We need to load attached objects to perform policy checks for files. | ||||
| // First, load the edges. | // First, load the edges. | ||||
| $edge_type = PhabricatorFileHasObjectEdgeType::EDGECONST; | $edge_type = PhabricatorFileHasObjectEdgeType::EDGECONST; | ||||
| $file_phids = mpull($files, 'getPHID'); | $file_phids = mpull($files, 'getPHID'); | ||||
| $edges = id(new PhabricatorEdgeQuery()) | $edges = id(new PhabricatorEdgeQuery()) | ||||
| ->withSourcePHIDs($file_phids) | ->withSourcePHIDs($file_phids) | ||||
| ->withEdgeTypes(array($edge_type)) | ->withEdgeTypes(array($edge_type)) | ||||
| ->execute(); | ->execute(); | ||||
| $object_phids = array(); | $object_phids = array(); | ||||
| foreach ($files as $file) { | foreach ($files as $file) { | ||||
| $phids = array_keys($edges[$file->getPHID()][$edge_type]); | $phids = array_keys($edges[$file->getPHID()][$edge_type]); | ||||
| $file->attachObjectPHIDs($phids); | $file->attachObjectPHIDs($phids); | ||||
| if ($file->getIsProfileImage()) { | if ($file->getIsProfileImage()) { | ||||
| // If this is a profile image, don't bother loading related files. | // If this is a profile image, don't bother loading related files. | ||||
| // It will always be visible, and we can get into trouble if we try | // It will always be visible, and we can get into trouble if we try | ||||
| // to load objects and end up stuck in a cycle. See T8478. | // to load objects and end up stuck in a cycle. See T8478. | ||||
| continue; | continue; | ||||
| } | } | ||||
| if ($is_omnipotent) { | |||||
| // If the viewer is omnipotent, we don't need to load the associated | |||||
| // objects either since they can certainly see the object. Skipping | |||||
| // this can improve performance and prevent cycles. | |||||
| continue; | |||||
| } | |||||
| foreach ($phids as $phid) { | foreach ($phids as $phid) { | ||||
| $object_phids[$phid] = true; | $object_phids[$phid] = true; | ||||
| } | } | ||||
| } | } | ||||
| // If this file is a transform of another file, load that file too. If you | // 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. | // can see the original file, you can see the thumbnail. | ||||
| ▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines | |||||