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

Add `diffusion.querycommits` and deprecate `diffusion.getcommits`

Summary:
Fixes T4344. `diffusion.getcommits` is nasty old bad news. Implement a modern query method.

This method provides limit/paging in a somewhat abstract way so it's sort of ultramodern, but I didn't want the default behavior to return a million rows. I'll probably move more stuff toward this over time, now that cursor paging is pervasive. Here, we needed extra metadata (the identifier map) anyway.

Test Plan: Used console to execute command.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4344

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

+156 -4
+2
src/__phutil_library_map__.php
··· 168 168 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_lastmodifiedquery_Method.php', 169 169 'ConduitAPI_diffusion_looksoon_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_looksoon_Method.php', 170 170 'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_mergedcommitsquery_Method.php', 171 + 'ConduitAPI_diffusion_querycommits_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_querycommits.php', 171 172 'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php', 172 173 'ConduitAPI_diffusion_readmequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_readmequery_Method.php', 173 174 'ConduitAPI_diffusion_refsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php', ··· 2637 2638 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2638 2639 'ConduitAPI_diffusion_looksoon_Method' => 'ConduitAPI_diffusion_Method', 2639 2640 'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2641 + 'ConduitAPI_diffusion_querycommits_Method' => 'ConduitAPI_diffusion_Method', 2640 2642 'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2641 2643 'ConduitAPI_diffusion_readmequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 2642 2644 'ConduitAPI_diffusion_refsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
+58 -2
src/applications/conduit/method/ConduitAPIMethod.php
··· 1 1 <?php 2 2 3 3 /** 4 - * 5 4 * @task status Method Status 6 - * @group conduit 5 + * @task pager Paging Results 7 6 */ 8 7 abstract class ConduitAPIMethod 9 8 extends Phobject ··· 164 163 "same URI to identify the install. Edit your .arcconfig or ". 165 164 "phabricator/conf so they agree on the URI for the install."); 166 165 } 166 + } 167 + 168 + 169 + /* -( Paging Results )----------------------------------------------------- */ 170 + 171 + 172 + /** 173 + * @task pager 174 + */ 175 + protected function getPagerParamTypes() { 176 + return array( 177 + 'before' => 'optional string', 178 + 'after' => 'optional string', 179 + 'limit' => 'optional int (default = 100)', 180 + ); 181 + } 182 + 183 + 184 + /** 185 + * @task pager 186 + */ 187 + protected function newPager(ConduitAPIRequest $request) { 188 + $limit = $request->getValue('limit', 100); 189 + $limit = min(1000, $limit); 190 + $limit = max(1, $limit); 191 + 192 + $pager = id(new AphrontCursorPagerView()) 193 + ->setPageSize($limit); 194 + 195 + $before_id = $request->getValue('before'); 196 + if ($before_id !== null) { 197 + $pager->setBeforeID($before_id); 198 + } 199 + 200 + $after_id = $request->getValue('after'); 201 + if ($after_id !== null) { 202 + $pager->setAfterID($after_id); 203 + } 204 + 205 + return $pager; 206 + } 207 + 208 + 209 + /** 210 + * @task pager 211 + */ 212 + protected function addPagerResults( 213 + array $results, 214 + AphrontCursorPagerView $pager) { 215 + 216 + $results['cursor'] = array( 217 + 'limit' => $pager->getPageSize(), 218 + 'after' => $pager->getNextPageID(), 219 + 'before' =>$pager->getPrevPageID(), 220 + ); 221 + 222 + return $results; 167 223 } 168 224 169 225
+9 -1
src/applications/diffusion/conduit/ConduitAPI_diffusion_getcommits_Method.php
··· 7 7 extends ConduitAPI_diffusion_Method { 8 8 9 9 public function getMethodDescription() { 10 - return "Retrieve Diffusion commit information."; 10 + return pht('Retrieve Diffusion commit information.'); 11 + } 12 + 13 + public function getMethodStatus() { 14 + return self::METHOD_STATUS_DEPRECATED; 15 + } 16 + 17 + public function getMethodStatusDescription() { 18 + return pht('Obsoleted by diffusion.querycommits.'); 11 19 } 12 20 13 21 public function defineParamTypes() {
+83
src/applications/diffusion/conduit/ConduitAPI_diffusion_querycommits_Method.php
··· 1 + <?php 2 + 3 + final class ConduitAPI_diffusion_querycommits_Method 4 + extends ConduitAPI_diffusion_Method { 5 + 6 + public function getMethodDescription() { 7 + return pht('Retrieve information about commits.'); 8 + } 9 + 10 + public function defineReturnType() { 11 + return 'map<string, dict>'; 12 + } 13 + 14 + public function defineParamTypes() { 15 + return array( 16 + 'ids' => 'optional list<int>', 17 + 'phids' => 'optional list<phid>', 18 + 'names' => 'optional list<string>', 19 + 'repositoryPHID' => 'optional phid', 20 + ) + $this->getPagerParamTypes(); 21 + } 22 + 23 + public function defineErrorTypes() { 24 + return array(); 25 + } 26 + 27 + protected function execute(ConduitAPIRequest $request) { 28 + $query = id(new DiffusionCommitQuery()) 29 + ->setViewer($request->getUser()); 30 + 31 + $repository_phid = $request->getValue('repositoryPHID'); 32 + if ($repository_phid) { 33 + $repository = id(new PhabricatorRepositoryQuery()) 34 + ->setViewer($request->getUser()) 35 + ->withPHIDs(array($repository_phid)) 36 + ->executeOne(); 37 + if ($repository) { 38 + $query->withRepository($repository); 39 + } 40 + } 41 + 42 + $names = $request->getValue('names'); 43 + if ($names) { 44 + $query->withIdentifiers($names); 45 + } 46 + 47 + $ids = $request->getValue('ids'); 48 + if ($ids) { 49 + $query->withIDs($ids); 50 + } 51 + 52 + $phids = $request->getValue('phids'); 53 + if ($phids) { 54 + $query->withPHIDs($phids); 55 + } 56 + 57 + $pager = $this->newPager($request); 58 + $commits = $query->executeWithCursorPager($pager); 59 + 60 + $map = $query->getIdentifierMap(); 61 + $map = mpull($map, 'getPHID'); 62 + 63 + $data = array(); 64 + foreach ($commits as $commit) { 65 + $data[$commit->getPHID()] = array( 66 + 'id' => $commit->getID(), 67 + 'phid' => $commit->getPHID(), 68 + 'repositoryPHID' => $commit->getRepository()->getPHID(), 69 + 'identifier' => $commit->getCommitIdentifier(), 70 + 'epoch' => $commit->getEpoch(), 71 + 'isImporting' => !$commit->isImported(), 72 + ); 73 + } 74 + 75 + $result = array( 76 + 'data' => $data, 77 + 'identifierMap' => nonempty($map, (object)array()), 78 + ); 79 + 80 + return $this->addPagerResults($result, $pager); 81 + } 82 + 83 + }
+4 -1
src/applications/diffusion/query/DiffusionCommitQuery.php
··· 259 259 // If we discarded all possible identifiers (e.g., they all referenced 260 260 // bogus repositories or were all too short), make sure the query finds 261 261 // nothing. 262 - throw new PhabricatorEmptyQueryException('No commit identifiers.'); 262 + throw new PhabricatorEmptyQueryException( 263 + pht('No commit identifiers.')); 263 264 } 264 265 265 266 $where[] = '('.implode(' OR ', $sql).')'; ··· 285 286 'repositoryID IN (%Ld)', 286 287 $this->repositoryIDs); 287 288 } 289 + 290 + $where[] = $this->buildPagingClause($conn_r); 288 291 289 292 return $this->formatWhereClause($where); 290 293 }