@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 the amount of weird "static" and "cache" behavior in Pholio query classes

Summary: Depends on D19922. Ref T11351. These query classes have some slightly weird behavior, including `public static function loadImages(...)`. Convert all this stuff into more standard query patterns.

Test Plan: Grepped for callsites, browsed around in Pholio.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T11351

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

+92 -85
+7 -4
src/applications/pholio/engine/PholioMockTimelineEngine.php
··· 7 7 $viewer = $this->getViewer(); 8 8 $object = $this->getObject(); 9 9 10 - PholioMockQuery::loadImages( 11 - $viewer, 12 - array($object), 13 - $need_inline_comments = true); 10 + $images = id(new PholioImageQuery()) 11 + ->setViewer($viewer) 12 + ->withMocks(array($object)) 13 + ->needInlineComments(true) 14 + ->execute(); 15 + 16 + $object->attachImages($images); 14 17 15 18 return id(new PholioTransactionView()) 16 19 ->setMock($object);
+41 -25
src/applications/pholio/query/PholioImageQuery.php
··· 6 6 private $ids; 7 7 private $phids; 8 8 private $mockPHIDs; 9 + private $mocks; 9 10 10 11 private $needInlineComments; 11 - private $mockCache = array(); 12 12 13 13 public function withIDs(array $ids) { 14 14 $this->ids = $ids; ··· 20 20 return $this; 21 21 } 22 22 23 + public function withMocks(array $mocks) { 24 + assert_instances_of($mocks, 'PholioMock'); 25 + 26 + $mocks = mpull($mocks, null, 'getPHID'); 27 + $this->mocks = $mocks; 28 + $this->mockPHIDs = array_keys($mocks); 29 + 30 + return $this; 31 + } 32 + 23 33 public function withMockPHIDs(array $mock_phids) { 24 34 $this->mockPHIDs = $mock_phids; 25 35 return $this; ··· 28 38 public function needInlineComments($need_inline_comments) { 29 39 $this->needInlineComments = $need_inline_comments; 30 40 return $this; 31 - } 32 - 33 - public function setMockCache($mock_cache) { 34 - $this->mockCache = $mock_cache; 35 - return $this; 36 - } 37 - public function getMockCache() { 38 - return $this->mockCache; 39 41 } 40 42 41 43 public function newResultObject() { ··· 76 78 protected function willFilterPage(array $images) { 77 79 assert_instances_of($images, 'PholioImage'); 78 80 79 - if ($this->getMockCache()) { 80 - $mocks = $this->getMockCache(); 81 - } else { 82 - $mock_phids = mpull($images, 'getMockPHID'); 81 + $mock_phids = array(); 82 + foreach ($images as $image) { 83 + if (!$image->hasMock()) { 84 + continue; 85 + } 83 86 84 - // DO NOT set needImages to true; recursion results! 85 - $mocks = id(new PholioMockQuery()) 86 - ->setViewer($this->getViewer()) 87 - ->withPHIDs($mock_phids) 88 - ->execute(); 87 + $mock_phids[] = $image->getMockPHID(); 88 + } 89 + 90 + if ($mock_phids) { 91 + if ($this->mocks) { 92 + $mocks = $this->mocks; 93 + } else { 94 + $mocks = id(new PholioMockQuery()) 95 + ->setViewer($this->getViewer()) 96 + ->withPHIDs($mock_phids) 97 + ->execute(); 98 + } 99 + 89 100 $mocks = mpull($mocks, null, 'getPHID'); 90 - } 101 + 102 + foreach ($images as $key => $image) { 103 + if (!$image->hasMock()) { 104 + continue; 105 + } 91 106 92 - foreach ($images as $index => $image) { 93 - $mock = idx($mocks, $image->getMockPHID()); 94 - if ($mock) { 107 + $mock = idx($mocks, $image->getMockPHID()); 108 + if (!$mock) { 109 + unset($images[$key]); 110 + $this->didRejectResult($image); 111 + continue; 112 + } 113 + 95 114 $image->attachMock($mock); 96 - } else { 97 - // mock is missing or we can't see it 98 - unset($images[$index]); 99 115 } 100 116 } 101 117
+43 -55
src/applications/pholio/query/PholioMockQuery.php
··· 58 58 } 59 59 60 60 protected function loadPage() { 61 - $mocks = $this->loadStandardPage($this->newResultObject()); 62 - 63 - if ($mocks && $this->needImages) { 64 - self::loadImages($this->getViewer(), $mocks, $this->needInlineComments); 61 + if ($this->needInlineComments && !$this->needImages) { 62 + throw new Exception( 63 + pht( 64 + 'You can not query for inline comments without also querying for '. 65 + 'images.')); 65 66 } 66 67 67 - if ($mocks && $this->needCoverFiles) { 68 - $this->loadCoverFiles($mocks); 69 - } 70 - 71 - if ($mocks && $this->needTokenCounts) { 72 - $this->loadTokenCounts($mocks); 73 - } 74 - 75 - return $mocks; 68 + return $this->loadStandardPage(new PholioMock()); 76 69 } 77 70 78 71 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { ··· 109 102 return $where; 110 103 } 111 104 112 - public static function loadImages( 113 - PhabricatorUser $viewer, 114 - array $mocks, 115 - $need_inline_comments) { 116 - assert_instances_of($mocks, 'PholioMock'); 117 - 118 - $mock_map = mpull($mocks, null, 'getPHID'); 119 - $all_images = id(new PholioImageQuery()) 120 - ->setViewer($viewer) 121 - ->setMockCache($mock_map) 122 - ->withMockPHIDs(array_keys($mock_map)) 123 - ->needInlineComments($need_inline_comments) 124 - ->execute(); 105 + protected function didFilterPage(array $mocks) { 106 + $viewer = $this->getViewer(); 125 107 126 - $image_groups = mgroup($all_images, 'getMockPHID'); 108 + if ($this->needImages) { 109 + $images = id(new PholioImageQuery()) 110 + ->setViewer($viewer) 111 + ->withMocks($mocks) 112 + ->needInlineComments($this->needInlineComments) 113 + ->execute(); 127 114 128 - foreach ($mocks as $mock) { 129 - $mock_images = idx($image_groups, $mock->getPHID(), array()); 130 - $mock->attachImages($mock_images); 115 + $image_groups = mgroup($images, 'getMockPHID'); 116 + foreach ($mocks as $mock) { 117 + $images = idx($image_groups, $mock->getPHID(), array()); 118 + $mock->attachImages($images); 119 + } 131 120 } 132 - } 133 121 134 - private function loadCoverFiles(array $mocks) { 135 - assert_instances_of($mocks, 'PholioMock'); 136 - $cover_file_phids = mpull($mocks, 'getCoverPHID'); 137 - $cover_files = id(new PhabricatorFileQuery()) 138 - ->setViewer($this->getViewer()) 139 - ->withPHIDs($cover_file_phids) 140 - ->execute(); 141 - 142 - $cover_files = mpull($cover_files, null, 'getPHID'); 122 + if ($this->needCoverFiles) { 123 + $cover_files = id(new PhabricatorFileQuery()) 124 + ->setViewer($viewer) 125 + ->withPHIDs(mpull($mocks, 'getCoverPHID')) 126 + ->execute(); 127 + $cover_files = mpull($cover_files, null, 'getPHID'); 143 128 144 - foreach ($mocks as $mock) { 145 - $file = idx($cover_files, $mock->getCoverPHID()); 146 - if (!$file) { 147 - $file = PhabricatorFile::loadBuiltin($this->getViewer(), 'missing.png'); 129 + foreach ($mocks as $mock) { 130 + $file = idx($cover_files, $mock->getCoverPHID()); 131 + if (!$file) { 132 + $file = PhabricatorFile::loadBuiltin( 133 + $viewer, 134 + 'missing.png'); 135 + } 136 + $mock->attachCoverFile($file); 148 137 } 149 - $mock->attachCoverFile($file); 150 138 } 151 - } 152 139 153 - private function loadTokenCounts(array $mocks) { 154 - assert_instances_of($mocks, 'PholioMock'); 155 - 156 - $phids = mpull($mocks, 'getPHID'); 157 - $counts = id(new PhabricatorTokenCountQuery()) 158 - ->withObjectPHIDs($phids) 159 - ->execute(); 140 + if ($this->needTokenCounts) { 141 + $counts = id(new PhabricatorTokenCountQuery()) 142 + ->withObjectPHIDs(mpull($mocks, 'getPHID')) 143 + ->execute(); 160 144 161 - foreach ($mocks as $mock) { 162 - $mock->attachTokenCount(idx($counts, $mock->getPHID(), 0)); 145 + foreach ($mocks as $mock) { 146 + $token_count = idx($counts, $mock->getPHID(), 0); 147 + $mock->attachTokenCount($token_count); 148 + } 163 149 } 150 + 151 + return $mocks; 164 152 } 165 153 166 154 public function getQueryApplicationClass() {
+1 -1
src/applications/pholio/view/PholioMockImagesView.php
··· 110 110 ); 111 111 } 112 112 113 - $ids = mpull($mock->getActiveImages(), 'getID'); 113 + $ids = mpull($mock->getActiveImages(), null, 'getID'); 114 114 if ($this->imageID && isset($ids[$this->imageID])) { 115 115 $selected_id = $this->imageID; 116 116 } else {