@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Reduce PhabricatorUser::getOmnipotentUser calls by adding a getViewer method to PhbaricatorDestructionEngine

Summary:
Fixes T6956. Before this change, we called PhabricatorUser::getOmnipotentUser in the various delete methods to query the data. Now, we use $engine->getViewer(), since its always a good thing to have less calls to PhabricatorUser::getOmnipotentUser thrown around the codebase.

I used the "codemod" tool to audit the existing calls to PhabricatorDestructorEngine (all of them) so ostensibly this gets all the spots. If I missed something though, its still going to work, so this change is very low risk.

Test Plan: ./bin/remove destroy P1; visit P1 and get a 404

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6956

Differential Revision: https://secure.phabricator.com/D12866

+14 -10
+1 -1
src/applications/almanac/storage/AlmanacDevice.php
··· 240 240 PhabricatorDestructionEngine $engine) { 241 241 242 242 $interfaces = id(new AlmanacInterfaceQuery()) 243 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 243 + ->setViewer($engine->getViewer()) 244 244 ->withDevicePHIDs(array($this->getPHID())) 245 245 ->execute(); 246 246 foreach ($interfaces as $interface) {
+1 -1
src/applications/almanac/storage/AlmanacInterface.php
··· 119 119 PhabricatorDestructionEngine $engine) { 120 120 121 121 $bindings = id(new AlmanacBindingQuery()) 122 - ->setViewer($this->getViewer()) 122 + ->setViewer($engine->getViewer()) 123 123 ->withInterfacePHIDs(array($this->getPHID())) 124 124 ->execute(); 125 125 foreach ($bindings as $binding) {
+1 -1
src/applications/almanac/storage/AlmanacNetwork.php
··· 103 103 PhabricatorDestructionEngine $engine) { 104 104 105 105 $interfaces = id(new AlmanacInterfaceQuery()) 106 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 106 + ->setViewer($engine->getViewer()) 107 107 ->withNetworkPHIDs(array($this->getPHID())) 108 108 ->execute(); 109 109
+1 -1
src/applications/almanac/storage/AlmanacService.php
··· 221 221 PhabricatorDestructionEngine $engine) { 222 222 223 223 $bindings = id(new AlmanacBindingQuery()) 224 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 224 + ->setViewer($engine->getViewer()) 225 225 ->withServicePHIDs(array($this->getPHID())) 226 226 ->execute(); 227 227 foreach ($bindings as $binding) {
+1 -1
src/applications/differential/storage/DifferentialRevision.php
··· 550 550 551 551 $this->openTransaction(); 552 552 $diffs = id(new DifferentialDiffQuery()) 553 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 553 + ->setViewer($engine->getViewer()) 554 554 ->withRevisionIDs(array($this->getID())) 555 555 ->execute(); 556 556 foreach ($diffs as $diff) {
+1 -1
src/applications/diviner/storage/DivinerLiveBook.php
··· 91 91 92 92 $this->openTransaction(); 93 93 $atoms = id(new DivinerAtomQuery()) 94 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 94 + ->setViewer($engine->getViewer()) 95 95 ->withBookPHIDs(array($this->getPHID())) 96 96 ->withIncludeGhosts(true) 97 97 ->withIncludeUndocumentable(true)
+2 -2
src/applications/files/controller/PhabricatorFileTransformController.php
··· 104 104 } 105 105 106 106 private function destroyTransform(PhabricatorTransformedFile $xform) { 107 + $engine = new PhabricatorDestructionEngine(); 107 108 $file = id(new PhabricatorFileQuery()) 108 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 109 + ->setViewer($engine->getViewer()) 109 110 ->withPHIDs(array($xform->getTransformedPHID())) 110 111 ->executeOne(); 111 112 ··· 114 115 if (!$file) { 115 116 $xform->delete(); 116 117 } else { 117 - $engine = new PhabricatorDestructionEngine(); 118 118 $engine->destroyObject($file); 119 119 } 120 120
+1 -1
src/applications/files/storage/PhabricatorFileChunk.php
··· 91 91 $data_phid = $this->getDataFilePHID(); 92 92 if ($data_phid) { 93 93 $data_file = id(new PhabricatorFileQuery()) 94 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 94 + ->setViewer($engine->getViewer()) 95 95 ->withPHIDs(array($data_phid)) 96 96 ->executeOne(); 97 97 if ($data_file) {
+1 -1
src/applications/paste/storage/PhabricatorPaste.php
··· 172 172 173 173 if ($this->filePHID) { 174 174 $file = id(new PhabricatorFileQuery()) 175 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 175 + ->setViewer($engine->getViewer()) 176 176 ->withPHIDs(array($this->filePHID)) 177 177 ->executeOne(); 178 178 if ($file) {
+4
src/applications/system/engine/PhabricatorDestructionEngine.php
··· 4 4 5 5 private $rootLogID; 6 6 7 + public function getViewer() { 8 + return PhabricatorUser::getOmnipotentUser(); 9 + } 10 + 7 11 public function destroyObject(PhabricatorDestructibleInterface $object) { 8 12 $log = id(new PhabricatorSystemDestructionLog()) 9 13 ->setEpoch(time())