Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/query/PhabricatorFileQuery.php
Show First 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | protected function loadPage() { | ||||
} | } | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$is_omnipotent = $viewer->isOmnipotent(); | $is_omnipotent = $viewer->isOmnipotent(); | ||||
// If we have any files left which do need objects, load the edges now. | // If we have any files left which do need objects, load the edges now. | ||||
$object_phids = array(); | $object_phids = array(); | ||||
if ($need_objects) { | if ($need_objects) { | ||||
$edge_type = PhabricatorFileHasObjectEdgeType::EDGECONST; | $attachments_map = $this->newAttachmentsMap($need_objects); | ||||
$file_phids = mpull($need_objects, 'getPHID'); | |||||
$edges = id(new PhabricatorEdgeQuery()) | |||||
->withSourcePHIDs($file_phids) | |||||
->withEdgeTypes(array($edge_type)) | |||||
->execute(); | |||||
foreach ($need_objects as $file) { | foreach ($need_objects as $file) { | ||||
$phids = array_keys($edges[$file->getPHID()][$edge_type]); | $file_phid = $file->getPHID(); | ||||
$phids = $attachments_map[$file_phid]; | |||||
$file->attachObjectPHIDs($phids); | $file->attachObjectPHIDs($phids); | ||||
if ($is_omnipotent) { | if ($is_omnipotent) { | ||||
// If the viewer is omnipotent, we don't need to load the associated | // If the viewer is omnipotent, we don't need to load the associated | ||||
// objects either since the viewer can certainly see the object. | // objects either since the viewer can certainly see the object. | ||||
// Skipping this can improve performance and prevent cycles. This | // Skipping this can improve performance and prevent cycles. This | ||||
// could possibly become part of the profile/builtin code above which | // could possibly become part of the profile/builtin code above which | ||||
// short circuits attacment policy checks in cases where we know them | // short circuits attacment policy checks in cases where we know them | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | foreach ($files as $key => $file) { | ||||
$original = null; | $original = null; | ||||
} | } | ||||
$file->attachOriginalFile($original); | $file->attachOriginalFile($original); | ||||
} | } | ||||
return $files; | return $files; | ||||
} | } | ||||
private function newAttachmentsMap(array $files) { | |||||
$file_phids = mpull($files, 'getPHID'); | |||||
$attachments_table = new PhabricatorFileAttachment(); | |||||
$attachments_conn = $attachments_table->establishConnection('r'); | |||||
$attachments = queryfx_all( | |||||
$attachments_conn, | |||||
'SELECT filePHID, objectPHID FROM %R WHERE filePHID IN (%Ls)', | |||||
$attachments_table, | |||||
$file_phids); | |||||
$attachments_map = array_fill_keys($file_phids, array()); | |||||
foreach ($attachments as $row) { | |||||
$file_phid = $row['filePHID']; | |||||
$object_phid = $row['objectPHID']; | |||||
$attachments_map[$file_phid][] = $object_phid; | |||||
} | |||||
return $attachments_map; | |||||
} | |||||
protected function didFilterPage(array $files) { | protected function didFilterPage(array $files) { | ||||
$xform_keys = $this->needTransforms; | $xform_keys = $this->needTransforms; | ||||
if ($xform_keys !== null) { | if ($xform_keys !== null) { | ||||
$xforms = id(new PhabricatorTransformedFile())->loadAllWhere( | $xforms = id(new PhabricatorTransformedFile())->loadAllWhere( | ||||
'originalPHID IN (%Ls) AND transform IN (%Ls)', | 'originalPHID IN (%Ls) AND transform IN (%Ls)', | ||||
mpull($files, 'getPHID'), | mpull($files, 'getPHID'), | ||||
$xform_keys); | $xform_keys); | ||||
▲ Show 20 Lines • Show All 205 Lines • Show Last 20 Lines |