From b872640c160a72f11cd69a11949877e182401f2c Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 12 May 2022 15:24:11 -0700 Subject: [PATCH] Remove all "FileHasObject" edge reads and writes Summary: Ref T13603. Removes all reads and writes to the other half of the legacy edge. Test Plan: - Verified I could still see file content accessible only through object attachment. - This fixes a unit test broken by removal of only half the edge access in the previous change. Maniphest Tasks: T13603 Differential Revision: https://secure.phabricator.com/D21820 --- .../files/query/PhabricatorFileQuery.php | 34 +++++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/applications/files/query/PhabricatorFileQuery.php b/src/applications/files/query/PhabricatorFileQuery.php index ea0dc0c35b..292507fdd1 100644 --- a/src/applications/files/query/PhabricatorFileQuery.php +++ b/src/applications/files/query/PhabricatorFileQuery.php @@ -209,16 +209,12 @@ final class PhabricatorFileQuery // If we have any files left which do need objects, load the edges now. $object_phids = array(); if ($need_objects) { - $edge_type = PhabricatorFileHasObjectEdgeType::EDGECONST; - $file_phids = mpull($need_objects, 'getPHID'); - - $edges = id(new PhabricatorEdgeQuery()) - ->withSourcePHIDs($file_phids) - ->withEdgeTypes(array($edge_type)) - ->execute(); + $attachments_map = $this->newAttachmentsMap($need_objects); 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); if ($is_omnipotent) { @@ -305,6 +301,28 @@ final class PhabricatorFileQuery 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) { $xform_keys = $this->needTransforms; if ($xform_keys !== null) { -- 2.11.4.GIT