@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.

Remove buildable handle / container handle logic form Harbormaster buildable queries

Summary:
Ref T10457. We currently have these weird, out-of-place methods on Harbormaster queries that just load handles. These were written before HandlePool, and HandlePool is now more convenient, simpler, and more efficient.

Drop this stuff in favor of using handle pools off `$viewer`.

Test Plan: Looked at buildable list, looked at buildable detail, grepped for removed methods.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10457

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

+60 -100
+6 -5
src/applications/harbormaster/controller/HarbormasterBuildableViewController.php
··· 9 9 $buildable = id(new HarbormasterBuildableQuery()) 10 10 ->setViewer($viewer) 11 11 ->withIDs(array($request->getURIData('id'))) 12 - ->needBuildableHandles(true) 13 - ->needContainerHandles(true) 14 12 ->executeOne(); 15 13 if (!$buildable) { 16 14 return new Aphront404Response(); ··· 167 165 ->setActionList($actions); 168 166 $box->addPropertyList($properties); 169 167 170 - if ($buildable->getContainerHandle() !== null) { 168 + $container_phid = $buildable->getContainerPHID(); 169 + $buildable_phid = $buildable->getBuildablePHID(); 170 + 171 + if ($container_phid) { 171 172 $properties->addProperty( 172 173 pht('Container'), 173 - $buildable->getContainerHandle()->renderLink()); 174 + $viewer->renderHandle($container_phid)); 174 175 } 175 176 176 177 $properties->addProperty( 177 178 pht('Buildable'), 178 - $buildable->getBuildableHandle()->renderLink()); 179 + $viewer->renderHandle($buildable_phid)); 179 180 180 181 $properties->addProperty( 181 182 pht('Origin'),
-1
src/applications/harbormaster/interface/HarbormasterBuildableInterface.php
··· 6 6 public function getHarbormasterContainerPHID(); 7 7 8 8 public function getBuildVariables(); 9 - 10 9 public function getAvailableBuildVariables(); 11 10 12 11 }
+20 -6
src/applications/harbormaster/phid/HarbormasterBuildablePHIDType.php
··· 21 21 array $phids) { 22 22 23 23 return id(new HarbormasterBuildableQuery()) 24 - ->withPHIDs($phids) 25 - ->needBuildableHandles(true); 24 + ->withPHIDs($phids); 26 25 } 27 26 28 27 public function loadHandles( ··· 30 29 array $handles, 31 30 array $objects) { 32 31 32 + $viewer = $this->getViewer(); 33 + 34 + $target_phids = array(); 35 + foreach ($objects as $phid => $object) { 36 + $target_phids[] = $object->getBuildablePHID(); 37 + } 38 + $target_handles = $viewer->loadHandles($target_phids); 39 + 33 40 foreach ($handles as $phid => $handle) { 34 41 $buildable = $objects[$phid]; 35 42 36 43 $id = $buildable->getID(); 37 - $target = $buildable->getBuildableHandle()->getFullName(); 44 + $buildable_phid = $buildable->getBuildablePHID(); 38 45 39 - $handle->setURI("/B{$id}"); 40 - $handle->setName("B{$id}"); 41 - $handle->setFullName("B{$id}: ".$target); 46 + $target = $target_handles[$buildable_phid]; 47 + $target_name = $target->getFullName(); 48 + 49 + $uri = $buildable->getURI(); 50 + $monogram = $buildable->getMonogram(); 51 + 52 + $handle 53 + ->setURI($uri) 54 + ->setName($monogram) 55 + ->setFullName("{$monogram}: {$target_name}"); 42 56 } 43 57 } 44 58
+9 -58
src/applications/harbormaster/query/HarbormasterBuildableQuery.php
··· 10 10 private $manualBuildables; 11 11 12 12 private $needContainerObjects; 13 - private $needContainerHandles; 14 - private $needBuildableHandles; 15 13 private $needBuilds; 16 14 private $needTargets; 17 15 ··· 42 40 43 41 public function needContainerObjects($need) { 44 42 $this->needContainerObjects = $need; 45 - return $this; 46 - } 47 - 48 - public function needContainerHandles($need) { 49 - $this->needContainerHandles = $need; 50 - return $this; 51 - } 52 - 53 - public function needBuildableHandles($need) { 54 - $this->needBuildableHandles = $need; 55 43 return $this; 56 44 } 57 45 ··· 99 87 } 100 88 101 89 protected function didFilterPage(array $page) { 102 - if ($this->needContainerObjects || $this->needContainerHandles) { 90 + if ($this->needContainerObjects) { 103 91 $container_phids = array_filter(mpull($page, 'getContainerPHID')); 104 92 105 - if ($this->needContainerObjects) { 106 - $containers = array(); 107 - 108 - if ($container_phids) { 109 - $containers = id(new PhabricatorObjectQuery()) 110 - ->setViewer($this->getViewer()) 111 - ->withPHIDs($container_phids) 112 - ->setParentQuery($this) 113 - ->execute(); 114 - $containers = mpull($containers, null, 'getPHID'); 115 - } 116 - 117 - foreach ($page as $key => $buildable) { 118 - $container_phid = $buildable->getContainerPHID(); 119 - $buildable->attachContainerObject(idx($containers, $container_phid)); 120 - } 121 - } 122 - 123 - if ($this->needContainerHandles) { 124 - $handles = array(); 125 - 126 - if ($container_phids) { 127 - $handles = id(new PhabricatorHandleQuery()) 128 - ->setViewer($this->getViewer()) 129 - ->withPHIDs($container_phids) 130 - ->setParentQuery($this) 131 - ->execute(); 132 - } 133 - 134 - foreach ($page as $key => $buildable) { 135 - $container_phid = $buildable->getContainerPHID(); 136 - $buildable->attachContainerHandle(idx($handles, $container_phid)); 137 - } 138 - } 139 - } 140 - 141 - if ($this->needBuildableHandles) { 142 - $handles = array(); 143 - 144 - $handle_phids = array_filter(mpull($page, 'getBuildablePHID')); 145 - if ($handle_phids) { 146 - $handles = id(new PhabricatorHandleQuery()) 93 + if ($container_phids) { 94 + $containers = id(new PhabricatorObjectQuery()) 147 95 ->setViewer($this->getViewer()) 148 - ->withPHIDs($handle_phids) 96 + ->withPHIDs($container_phids) 149 97 ->setParentQuery($this) 150 98 ->execute(); 99 + $containers = mpull($containers, null, 'getPHID'); 100 + } else { 101 + $containers = array(); 151 102 } 152 103 153 104 foreach ($page as $key => $buildable) { 154 - $handle_phid = $buildable->getBuildablePHID(); 155 - $buildable->attachBuildableHandle(idx($handles, $handle_phid)); 105 + $container_phid = $buildable->getContainerPHID(); 106 + $buildable->attachContainerObject(idx($containers, $container_phid)); 156 107 } 157 108 } 158 109
+21 -10
src/applications/harbormaster/query/HarbormasterBuildableSearchEngine.php
··· 58 58 } 59 59 60 60 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 61 - $query = id(new HarbormasterBuildableQuery()) 62 - ->needContainerHandles(true) 63 - ->needBuildableHandles(true); 61 + $query = id(new HarbormasterBuildableQuery()); 64 62 65 63 $container_phids = $saved->getParameter('containerPHIDs', array()); 66 64 if ($container_phids) { ··· 185 183 186 184 $viewer = $this->requireViewer(); 187 185 186 + $phids = array(); 187 + foreach ($buildables as $buildable) { 188 + $phids[] = $buildable->getContainerPHID(); 189 + $phids[] = $buildable->getBuildablePHID(); 190 + } 191 + $handles = $viewer->loadHandles($phids); 192 + 193 + 188 194 $list = new PHUIObjectItemListView(); 189 195 foreach ($buildables as $buildable) { 190 196 $id = $buildable->getID(); 197 + 198 + $container_phid = $buildable->getContainerPHID(); 199 + $buildable_phid = $buildable->getBuildablePHID(); 191 200 192 201 $item = id(new PHUIObjectItemView()) 193 202 ->setHeader(pht('Buildable %d', $buildable->getID())); 194 - if ($buildable->getContainerHandle() !== null) { 195 - $item->addAttribute($buildable->getContainerHandle()->getName()); 203 + 204 + if ($container_phid) { 205 + $handle = $handles[$container_phid]; 206 + $item->addAttribute($handle->getName()); 196 207 } 197 - if ($buildable->getBuildableHandle() !== null) { 198 - $item->addAttribute($buildable->getBuildableHandle()->getFullName()); 208 + 209 + if ($buildable_phid) { 210 + $handle = $handles[$buildable_phid]; 211 + $item->addAttribute($handle->getFullName()); 199 212 } 200 213 201 - if ($id) { 202 - $item->setHref("/B{$id}"); 203 - } 214 + $item->setHref($buildable->getURI()); 204 215 205 216 if ($buildable->getIsManualBuildable()) { 206 217 $item->addIcon('fa-wrench grey', pht('Manual'));
+4 -20
src/applications/harbormaster/storage/HarbormasterBuildable.php
··· 13 13 14 14 private $buildableObject = self::ATTACHABLE; 15 15 private $containerObject = self::ATTACHABLE; 16 - private $buildableHandle = self::ATTACHABLE; 17 - private $containerHandle = self::ATTACHABLE; 18 16 private $builds = self::ATTACHABLE; 19 17 20 18 const STATUS_BUILDING = 'building'; ··· 68 66 69 67 public function getMonogram() { 70 68 return 'B'.$this->getID(); 69 + } 70 + 71 + public function getURI() { 72 + return '/'.$this->getMonogram(); 71 73 } 72 74 73 75 /** ··· 235 237 236 238 public function getContainerObject() { 237 239 return $this->assertAttached($this->containerObject); 238 - } 239 - 240 - public function attachContainerHandle($container_handle) { 241 - $this->containerHandle = $container_handle; 242 - return $this; 243 - } 244 - 245 - public function getContainerHandle() { 246 - return $this->assertAttached($this->containerHandle); 247 - } 248 - 249 - public function attachBuildableHandle($buildable_handle) { 250 - $this->buildableHandle = $buildable_handle; 251 - return $this; 252 - } 253 - 254 - public function getBuildableHandle() { 255 - return $this->assertAttached($this->buildableHandle); 256 240 } 257 241 258 242 public function attachBuilds(array $builds) {