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

Support a "withPaths()" API in DifferentialRevisionQuery, and use it on the revision view

Summary: Ref T13639. Move away from "withPath(..., ...)" to "withPaths(...)".

Test Plan: {F8539323}

Maniphest Tasks: T13639

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

+78 -13
+11 -13
src/applications/differential/controller/DifferentialRevisionViewController.php
··· 986 986 PhabricatorRepository $repository) { 987 987 assert_instances_of($changesets, 'DifferentialChangeset'); 988 988 989 + $viewer = $this->getViewer(); 990 + 989 991 $paths = array(); 990 992 foreach ($changesets as $changeset) { 991 993 $paths[] = $changeset->getAbsoluteRepositoryPath( ··· 997 999 return array(); 998 1000 } 999 1001 1000 - $path_map = id(new DiffusionPathIDQuery($paths))->loadPathIDs(); 1001 - 1002 - if (!$path_map) { 1003 - return array(); 1004 - } 1005 - 1006 1002 $recent = (PhabricatorTime::getNow() - phutil_units('30 days in seconds')); 1007 1003 1008 1004 $query = id(new DifferentialRevisionQuery()) 1009 - ->setViewer($this->getRequest()->getUser()) 1005 + ->setViewer($viewer) 1010 1006 ->withIsOpen(true) 1011 1007 ->withUpdatedEpochBetween($recent, null) 1012 1008 ->setOrder(DifferentialRevisionQuery::ORDER_MODIFIED) 1013 1009 ->setLimit(10) 1014 1010 ->needFlags(true) 1015 1011 ->needDrafts(true) 1016 - ->needReviewers(true); 1017 - 1018 - foreach ($path_map as $path => $path_id) { 1019 - $query->withPath($repository->getID(), $path_id); 1020 - } 1012 + ->needReviewers(true) 1013 + ->withRepositoryPHIDs( 1014 + array( 1015 + $repository->getPHID(), 1016 + )) 1017 + ->withPaths($paths); 1021 1018 1022 1019 $results = $query->execute(); 1023 1020 1024 1021 // Strip out *this* revision. 1025 1022 foreach ($results as $key => $result) { 1026 1023 if ($result->getID() == $this->revisionID) { 1027 - unset($results[$key]); 1024 + unset($results[$key]); 1025 + break; 1028 1026 } 1029 1027 } 1030 1028
+67
src/applications/differential/query/DifferentialRevisionQuery.php
··· 27 27 private $createdEpochMin; 28 28 private $createdEpochMax; 29 29 private $noReviewers; 30 + private $paths; 30 31 31 32 const ORDER_MODIFIED = 'order-modified'; 32 33 const ORDER_CREATED = 'order-created'; ··· 59 60 'repositoryID' => $repository_id, 60 61 'pathID' => $path_id, 61 62 ); 63 + return $this; 64 + } 65 + 66 + /** 67 + * Find revisions affecting one or more items in a list of paths. 68 + * 69 + * @param list<string> List of file paths. 70 + * @return this 71 + * @task config 72 + */ 73 + public function withPaths(array $paths) { 74 + $this->paths = $paths; 62 75 return $this; 63 76 } 64 77 ··· 576 589 $path_table->getTableName()); 577 590 } 578 591 592 + if ($this->paths) { 593 + $path_table = new DifferentialAffectedPath(); 594 + $joins[] = qsprintf( 595 + $conn, 596 + 'JOIN %R paths ON paths.revisionID = r.id', 597 + $path_table); 598 + } 599 + 579 600 if ($this->commitHashes) { 580 601 $joins[] = qsprintf( 581 602 $conn, ··· 635 656 * @task internal 636 657 */ 637 658 protected function buildWhereClause(AphrontDatabaseConnection $conn) { 659 + $viewer = $this->getViewer(); 638 660 $where = array(); 639 661 640 662 if ($this->pathIDs) { ··· 649 671 } 650 672 $path_clauses = qsprintf($conn, '%LO', $path_clauses); 651 673 $where[] = $path_clauses; 674 + } 675 + 676 + if ($this->paths !== null) { 677 + $paths = $this->paths; 678 + 679 + $path_map = id(new DiffusionPathIDQuery($paths)) 680 + ->loadPathIDs(); 681 + 682 + if (!$path_map) { 683 + // If none of the paths have entries in the PathID table, we can not 684 + // possibly find any revisions affecting them. 685 + throw new PhabricatorEmptyQueryException(); 686 + } 687 + 688 + $where[] = qsprintf( 689 + $conn, 690 + 'paths.pathID IN (%Ld)', 691 + array_fuse($path_map)); 692 + 693 + // If we have repository PHIDs, additionally constrain this query to 694 + // try to help MySQL execute it efficiently. 695 + if ($this->repositoryPHIDs !== null) { 696 + $repositories = id(new PhabricatorRepositoryQuery()) 697 + ->setViewer($viewer) 698 + ->setParentQuery($this) 699 + ->withPHIDs($this->repositoryPHIDs) 700 + ->execute(); 701 + 702 + if (!$repositories) { 703 + throw new PhabricatorEmptyQueryException(); 704 + } 705 + 706 + $repository_ids = mpull($repositories, 'getID'); 707 + 708 + $where[] = qsprintf( 709 + $conn, 710 + 'paths.repositoryID IN (%Ld)', 711 + $repository_ids); 712 + } 652 713 } 653 714 654 715 if ($this->authors) { ··· 779 840 protected function shouldGroupQueryResultRows() { 780 841 781 842 if (count($this->pathIDs) > 1) { 843 + return true; 844 + } 845 + 846 + if ($this->paths) { 847 + // (If we have exactly one repository and exactly one path, we don't 848 + // technically need to group, but it's simpler to always group.) 782 849 return true; 783 850 } 784 851