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

Improve implementation of ManiphestTaskQuery

Summary:
Currently, we have a single `projectPHIDs` field, and a separate flag which makes it act like AND or OR.

This is silly. Make two separate methods for setting `AND` vs `OR` projects. This also simplifies the implmentation.

This doesn't change the UI or any behavior (yet), it just makes the API more usable.

Test Plan: Loaded homepage, "All Projects" task view, verified queries made sense and returned correct results. Grepped for changed method name.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1610

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

+63 -42
+1 -2
src/applications/directory/controller/PhabricatorDirectoryMainController.php
··· 247 247 $task_query = new ManiphestTaskQuery(); 248 248 $task_query->withStatus(ManiphestTaskQuery::STATUS_OPEN); 249 249 $task_query->withPriority(ManiphestTaskPriority::PRIORITY_TRIAGE); 250 - $task_query->withProjects(mpull($projects, 'getPHID')); 251 - $task_query->withAnyProject(true); 250 + $task_query->withAnyProjects(mpull($projects, 'getPHID')); 252 251 $task_query->setLimit(10); 253 252 $tasks = $task_query->execute(); 254 253 } else {
+47 -27
src/applications/maniphest/ManiphestTaskQuery.php
··· 22 22 * 23 23 * @group maniphest 24 24 */ 25 - final class ManiphestTaskQuery { 25 + final class ManiphestTaskQuery extends PhabricatorQuery { 26 26 27 27 private $taskIDs = array(); 28 28 private $authorPHIDs = array(); ··· 31 31 private $projectPHIDs = array(); 32 32 private $xprojectPHIDs = array(); 33 33 private $subscriberPHIDs = array(); 34 - private $anyProject = false; 34 + private $anyProjectPHIDs = array(); 35 35 private $includeNoProject = null; 36 36 37 37 private $fullTextSearch = ''; ··· 179 179 return $this->groupByProjectResults; 180 180 } 181 181 182 - public function withAnyProject($any_project) { 183 - $this->anyProject = $any_project; 182 + public function withAnyProjects(array $projects) { 183 + $this->anyProjectPHIDs = $projects; 184 184 return $this; 185 185 } 186 186 ··· 203 203 $where[] = $this->buildOwnerWhereClause($conn); 204 204 $where[] = $this->buildSubscriberWhereClause($conn); 205 205 $where[] = $this->buildProjectWhereClause($conn); 206 + $where[] = $this->buildAnyProjectWhereClause($conn); 206 207 $where[] = $this->buildXProjectWhereClause($conn); 207 208 $where[] = $this->buildFullTextWhereClause($conn); 208 209 209 - $where = array_filter($where); 210 - if ($where) { 211 - $where = 'WHERE ('.implode(') AND (', $where).')'; 212 - } else { 213 - $where = ''; 214 - } 210 + $where = $this->formatWhereClause($where); 215 211 216 212 $join = array(); 217 213 $join[] = $this->buildProjectJoinClause($conn); 214 + $join[] = $this->buildAnyProjectJoinClause($conn); 218 215 $join[] = $this->buildXProjectJoinClause($conn); 219 216 $join[] = $this->buildSubscriberJoinClause($conn); 220 217 ··· 228 225 $having = ''; 229 226 $count = ''; 230 227 $group = ''; 231 - if (count($this->projectPHIDs) > 1) { 232 228 233 - // If we're searching for more than one project: 234 - // - We'll get multiple rows for tasks when they join the project table 235 - // multiple times. We use GROUP BY to make them distinct again. 236 - // - We want to treat the query as an intersection query, not a union 237 - // query. We sum the project count and require it be the same as the 238 - // number of projects we're searching for. (If 'anyProject' is set, 239 - // we do union instead.) 240 - 229 + if (count($this->projectPHIDs) > 1 || count($this->anyProjectPHIDs) > 1) { 230 + // If we're joining multiple rows, we need to group the results by the 231 + // task IDs. 241 232 $group = 'GROUP BY task.id'; 233 + } else { 234 + $group = ''; 235 + } 242 236 243 - if (!$this->anyProject) { 244 - $count = ', COUNT(project.projectPHID) projectCount'; 245 - $having = qsprintf( 246 - $conn, 247 - 'HAVING projectCount = %d', 248 - count($this->projectPHIDs)); 249 - } 237 + if (count($this->projectPHIDs) > 1) { 238 + // We want to treat the query as an intersection query, not a union 239 + // query. We sum the project count and require it be the same as the 240 + // number of projects we're searching for. 241 + 242 + $count = ', COUNT(project.projectPHID) projectCount'; 243 + $having = qsprintf( 244 + $conn, 245 + 'HAVING projectCount = %d', 246 + count($this->projectPHIDs)); 250 247 } 251 248 252 249 $order = $this->buildOrderClause($conn); ··· 456 453 $project_dao->getTableName()); 457 454 } 458 455 456 + private function buildAnyProjectWhereClause($conn) { 457 + if (!$this->anyProjectPHIDs) { 458 + return null; 459 + } 460 + 461 + return qsprintf( 462 + $conn, 463 + 'anyproject.projectPHID IN (%Ls)', 464 + $this->anyProjectPHIDs); 465 + } 466 + 467 + private function buildAnyProjectJoinClause($conn) { 468 + if (!$this->anyProjectPHIDs) { 469 + return null; 470 + } 471 + 472 + $project_dao = new ManiphestTaskProject(); 473 + return qsprintf( 474 + $conn, 475 + 'LEFT JOIN %T anyproject ON anyproject.taskPHID = task.phid', 476 + $project_dao->getTableName()); 477 + } 478 + 459 479 private function buildXProjectWhereClause($conn) { 460 480 if (!$this->xprojectPHIDs) { 461 481 return null; ··· 592 612 $ii = 0; 593 613 foreach ($tasks as $key => $task) { 594 614 $phids = $task->getProjectPHIDs(); 595 - if (!$this->anyProject && $this->projectPHIDs) { 615 + if ($this->projectPHIDs) { 596 616 $phids = array_diff($phids, $this->projectPHIDs); 597 617 } 598 618 if ($phids) {
+14 -11
src/applications/maniphest/controller/ManiphestTaskListController.php
··· 406 406 $any_project = false; 407 407 $search_text = $search_query->getParameter('fullTextSearch'); 408 408 $user_phids = $search_query->getParameter('userPHIDs', array()); 409 + $task_ids = $search_query->getParameter('taskIDs', array()); 409 410 $project_phids = $search_query->getParameter('projectPHIDs', array()); 410 - $task_ids = $search_query->getParameter('taskIDs', array()); 411 + $any_project_phids = $search_query->getParameter( 412 + 'anyProjectPHIDs', 413 + array()); 411 414 $xproject_phids = $search_query->getParameter( 412 415 'excludeProjectPHIDs', 413 416 array()); ··· 467 470 break; 468 471 case 'projecttriage': 469 472 $query->withPriority(ManiphestTaskPriority::PRIORITY_TRIAGE); 470 - $any_project = true; 473 + $query->withAnyProjects($any_project_phids); 471 474 break; 472 475 case 'projectall': 473 - $any_project = true; 476 + $query->withAnyProjects($any_project_phids); 474 477 break; 475 478 case 'custom': 476 479 $query->withPrioritiesBetween($low_priority, $high_priority); 477 480 break; 478 481 } 479 - 480 - $query->withAnyProject($any_project); 481 482 482 483 $query->withFullTextSearch($search_text); 483 484 ··· 689 690 array($user->getPHID())); 690 691 691 692 if ($this->view == 'projecttriage' || $this->view == 'projectall') { 692 - $project_query = new PhabricatorProjectQuery(); 693 - $project_query->setViewer($user); 694 - $project_query->withMemberPHIDs($user_phids); 695 - $projects = $project_query->execute(); 696 - $project_phids = mpull($projects, 'getPHID'); 693 + $projects = id(new PhabricatorProjectQuery()) 694 + ->setViewer($user) 695 + ->withMemberPHIDs($user_phids) 696 + ->execute(); 697 + $any_project_phids = mpull($projects, 'getPHID'); 697 698 } else { 698 - $project_phids = $request->getStrList('projects'); 699 + $any_project_phids = $request->getStrList('aprojects'); 699 700 } 700 701 702 + $project_phids = $request->getStrList('projects'); 701 703 $exclude_project_phids = $request->getStrList('xprojects'); 702 704 $task_ids = $request->getStrList('tasks'); 703 705 ··· 739 741 'view' => $this->view, 740 742 'userPHIDs' => $user_phids, 741 743 'projectPHIDs' => $project_phids, 744 + 'anyProjectPHIDs' => $any_project_phids, 742 745 'excludeProjectPHIDs' => $exclude_project_phids, 743 746 'ownerPHIDs' => $owner_phids, 744 747 'authorPHIDs' => $author_phids,
+1 -2
src/applications/project/controller/PhabricatorProjectListController.php
··· 84 84 $groups = array(); 85 85 if ($project_phids) { 86 86 $query = id(new ManiphestTaskQuery()) 87 - ->withProjects($project_phids) 88 - ->withAnyProject(true) 87 + ->withAnyProjects($project_phids) 89 88 ->withStatus(ManiphestTaskQuery::STATUS_OPEN) 90 89 ->setLimit(PHP_INT_MAX); 91 90