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

Fix issues where Drydock queries didn't work correctly with empty arrays

Summary: Ref T2015. This fixes issues where the Drydock queries wouldn't filter (or throw an exception) when passed empty arrays for their `with` methods. In addition, this also adds `array_unique` to the resource and lease subqueries so that we don't pull in a bunch of stuff if logs or leases have the same related objects.

Test Plan: Tested it by using DarkConsole on the log controller.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: joshuaspence, Korvin, epriestley

Maniphest Tasks: T2015

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

+49 -33
+3 -3
src/applications/drydock/query/DrydockBlueprintQuery.php
··· 51 51 protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 52 52 $where = array(); 53 53 54 - if ($this->ids) { 54 + if ($this->ids !== null) { 55 55 $where[] = qsprintf( 56 56 $conn_r, 57 57 'id IN (%Ld)', 58 58 $this->ids); 59 59 } 60 60 61 - if ($this->phids) { 61 + if ($this->phids !== null) { 62 62 $where[] = qsprintf( 63 63 $conn_r, 64 64 'phid IN (%Ls)', 65 65 $this->phids); 66 66 } 67 67 68 - if ($this->datasourceQuery) { 68 + if ($this->datasourceQuery !== null) { 69 69 $where[] = qsprintf( 70 70 $conn_r, 71 71 'blueprintName LIKE %>',
+6 -6
src/applications/drydock/query/DrydockLeaseQuery.php
··· 47 47 $resources = id(new DrydockResourceQuery()) 48 48 ->setParentQuery($this) 49 49 ->setViewer($this->getViewer()) 50 - ->withIDs($resource_ids) 50 + ->withIDs(array_unique($resource_ids)) 51 51 ->execute(); 52 52 } else { 53 53 $resources = array(); ··· 71 71 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 72 72 $where = parent::buildWhereClauseParts($conn); 73 73 74 - if ($this->resourceIDs) { 74 + if ($this->resourceIDs !== null) { 75 75 $where[] = qsprintf( 76 76 $conn, 77 77 'resourceID IN (%Ld)', 78 78 $this->resourceIDs); 79 79 } 80 80 81 - if ($this->ids) { 81 + if ($this->ids !== null) { 82 82 $where[] = qsprintf( 83 83 $conn, 84 84 'id IN (%Ld)', 85 85 $this->ids); 86 86 } 87 87 88 - if ($this->phids) { 88 + if ($this->phids !== null) { 89 89 $where[] = qsprintf( 90 90 $conn, 91 91 'phid IN (%Ls)', 92 92 $this->phids); 93 93 } 94 94 95 - if ($this->statuses) { 95 + if ($this->statuses !== null) { 96 96 $where[] = qsprintf( 97 97 $conn, 98 98 'status IN (%Ld)', 99 99 $this->statuses); 100 100 } 101 101 102 - if ($this->datasourceQuery) { 102 + if ($this->datasourceQuery !== null) { 103 103 $where[] = qsprintf( 104 104 $conn, 105 105 'id = %d',
+4 -4
src/applications/drydock/query/DrydockLogQuery.php
··· 36 36 $resources = id(new DrydockResourceQuery()) 37 37 ->setParentQuery($this) 38 38 ->setViewer($this->getViewer()) 39 - ->withIDs($resource_ids) 39 + ->withIDs(array_unique($resource_ids)) 40 40 ->execute(); 41 41 } else { 42 42 $resources = array(); ··· 59 59 $leases = id(new DrydockLeaseQuery()) 60 60 ->setParentQuery($this) 61 61 ->setViewer($this->getViewer()) 62 - ->withIDs($lease_ids) 62 + ->withIDs(array_unique($lease_ids)) 63 63 ->execute(); 64 64 } else { 65 65 $leases = array(); ··· 91 91 protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 92 92 $where = array(); 93 93 94 - if ($this->resourceIDs) { 94 + if ($this->resourceIDs !== null) { 95 95 $where[] = qsprintf( 96 96 $conn_r, 97 97 'resourceID IN (%Ld)', 98 98 $this->resourceIDs); 99 99 } 100 100 101 - if ($this->leaseIDs) { 101 + if ($this->leaseIDs !== null) { 102 102 $where[] = qsprintf( 103 103 $conn_r, 104 104 'leaseID IN (%Ld)',
+30 -14
src/applications/drydock/query/DrydockLogSearchEngine.php
··· 24 24 } 25 25 26 26 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 27 + $resource_phids = $saved->getParameter('resourcePHIDs', array()); 28 + $lease_phids = $saved->getParameter('leasePHIDs', array()); 27 29 28 - // TODO: Change logs to use PHIDs instead of IDs. 29 - $resource_ids = id(new DrydockResourceQuery()) 30 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 31 - ->withPHIDs($saved->getParameter('resourcePHIDs', array())) 32 - ->execute(); 33 - $resource_ids = mpull($resource_ids, 'getID'); 34 - $lease_ids = id(new DrydockLeaseQuery()) 35 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 36 - ->withPHIDs($saved->getParameter('leasePHIDs', array())) 37 - ->execute(); 38 - $lease_ids = mpull($lease_ids, 'getID'); 30 + // TODO: Change logs to use PHIDs instead of IDs. 31 + $resource_ids = array(); 32 + $lease_ids = array(); 39 33 40 - return id(new DrydockLogQuery()) 41 - ->withResourceIDs($resource_ids) 42 - ->withLeaseIDs($lease_ids); 34 + if ($resource_phids) { 35 + $resource_ids = id(new DrydockResourceQuery()) 36 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 37 + ->withPHIDs($resource_phids) 38 + ->execute(); 39 + $resource_ids = mpull($resource_ids, 'getID'); 40 + } 41 + 42 + if ($lease_phids) { 43 + $lease_ids = id(new DrydockLeaseQuery()) 44 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 45 + ->withPHIDs($lease_phids) 46 + ->execute(); 47 + $lease_ids = mpull($lease_ids, 'getID'); 48 + } 49 + 50 + $query = new DrydockLogQuery(); 51 + if ($resource_ids) { 52 + $query->withResourceIDs($resource_ids); 53 + } 54 + if ($lease_ids) { 55 + $query->withLeaseIDs($lease_ids); 56 + } 57 + 58 + return $query; 43 59 } 44 60 45 61 public function buildSearchForm(
+6 -6
src/applications/drydock/query/DrydockResourceQuery.php
··· 59 59 protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 60 60 $where = array(); 61 61 62 - if ($this->ids) { 62 + if ($this->ids !== null) { 63 63 $where[] = qsprintf( 64 64 $conn_r, 65 65 'id IN (%Ld)', 66 66 $this->ids); 67 67 } 68 68 69 - if ($this->phids) { 69 + if ($this->phids !== null) { 70 70 $where[] = qsprintf( 71 71 $conn_r, 72 72 'phid IN (%Ls)', 73 73 $this->phids); 74 74 } 75 75 76 - if ($this->types) { 76 + if ($this->types !== null) { 77 77 $where[] = qsprintf( 78 78 $conn_r, 79 79 'type IN (%Ls)', 80 80 $this->types); 81 81 } 82 82 83 - if ($this->statuses) { 83 + if ($this->statuses !== null) { 84 84 $where[] = qsprintf( 85 85 $conn_r, 86 86 'status IN (%Ls)', 87 87 $this->statuses); 88 88 } 89 89 90 - if ($this->blueprintPHIDs) { 90 + if ($this->blueprintPHIDs !== null) { 91 91 $where[] = qsprintf( 92 92 $conn_r, 93 93 'blueprintPHID IN (%Ls)', 94 94 $this->blueprintPHIDs); 95 95 } 96 96 97 - if ($this->datasourceQuery) { 97 + if ($this->datasourceQuery !== null) { 98 98 $where[] = qsprintf( 99 99 $conn_r, 100 100 'name LIKE %>',