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

Make JOIN changes to CommitQuery only

Summary:
Fixes T4911. See D8879. This gives us the correct query in cases where there are no audits.

This doesn't try to do the GROUP BY stuff yet.

Test Plan:
- Viewed a commit in Diffusion with no audits, got a commit detail page.
- Viewed "All Commits" in web UI, saw commits without any audits included in the list.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4911

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

+38 -17
+38 -17
src/applications/diffusion/query/DiffusionCommitQuery.php
··· 88 88 return $this; 89 89 } 90 90 91 - public function getAuditRequests() { 91 + /** 92 + * Retuns true if we should join the audit table, either because we're 93 + * interested in the information if it's available or because matching 94 + * rows must always have it. 95 + */ 96 + private function shouldJoinAudits() { 92 97 return 93 98 $this->needAuditRequests || 99 + $this->auditStatus || 100 + $this->rowsMustHaveAudits(); 101 + } 102 + 103 + 104 + /** 105 + * Return true if we should `JOIN` (vs `LEFT JOIN`) the audit table, because 106 + * matching commits will always have audit rows. 107 + */ 108 + private function rowsMustHaveAudits() { 109 + return 94 110 $this->auditIDs || 95 111 $this->auditorPHIDs || 96 - $this->auditAwaitingUser || 97 - $this->auditStatus; 112 + $this->auditAwaitingUser; 98 113 } 99 114 100 115 public function withAuditIDs(array $ids) { ··· 149 164 $this->buildOrderClause($conn_r), 150 165 $this->buildLimitClause($conn_r)); 151 166 152 - if ($this->getAuditRequests()) { 167 + if ($this->shouldJoinAudits()) { 153 168 $this->loadAuditIds = ipull($data, 'audit_id'); 154 169 } 155 170 ··· 157 172 } 158 173 159 174 private function buildAuditSelect($conn_r) { 160 - if ($this->getAuditRequests()) { 175 + if ($this->shouldJoinAudits()) { 161 176 return qsprintf( 162 177 $conn_r, 163 178 ', audit.id as audit_id'); ··· 239 254 } 240 255 } 241 256 242 - if ($this->getAuditRequests()) { 243 - $requests = id(new PhabricatorRepositoryAuditRequest()) 244 - ->loadAllWhere('id IN (%Ld)', $this->loadAuditIds); 257 + if ($this->shouldJoinAudits()) { 258 + $load_ids = array_filter($this->loadAuditIds); 259 + if ($load_ids) { 260 + $requests = id(new PhabricatorRepositoryAuditRequest()) 261 + ->loadAllWhere('id IN (%Ld)', $this->loadAuditIds); 262 + } else { 263 + $requests = array(); 264 + } 245 265 246 266 $requests = mgroup($requests, 'getCommitPHID'); 247 267 foreach ($commits as $commit) { ··· 259 279 private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 260 280 $where = array(); 261 281 262 - if ($this->ids) { 282 + if ($this->ids !== null) { 263 283 $where[] = qsprintf( 264 284 $conn_r, 265 285 'commit.id IN (%Ld)', 266 286 $this->ids); 267 287 } 268 288 269 - if ($this->phids) { 289 + if ($this->phids !== null) { 270 290 $where[] = qsprintf( 271 291 $conn_r, 272 292 'commit.phid IN (%Ls)', 273 293 $this->phids); 274 294 } 275 295 276 - if ($this->repositoryIDs) { 296 + if ($this->repositoryIDs !== null) { 277 297 $where[] = qsprintf( 278 298 $conn_r, 279 299 'commit.repositoryID IN (%Ld)', 280 300 $this->repositoryIDs); 281 301 } 282 302 283 - if ($this->authorPHIDs) { 303 + if ($this->authorPHIDs !== null) { 284 304 $where[] = qsprintf( 285 305 $conn_r, 286 306 'commit.authorPHID IN (%Ls)', 287 307 $this->authorPHIDs); 288 308 } 289 309 290 - if ($this->identifiers) { 310 + if ($this->identifiers !== null) { 291 311 $min_unqualified = PhabricatorRepository::MINIMUM_UNQUALIFIED_HASH; 292 312 $min_qualified = PhabricatorRepository::MINIMUM_QUALIFIED_HASH; 293 313 ··· 378 398 $where[] = '('.implode(' OR ', $sql).')'; 379 399 } 380 400 381 - if ($this->auditIDs) { 401 + if ($this->auditIDs !== null) { 382 402 $where[] = qsprintf( 383 403 $conn_r, 384 404 'audit.id IN (%Ld)', 385 405 $this->auditIDs); 386 406 } 387 407 388 - if ($this->auditorPHIDs) { 408 + if ($this->auditorPHIDs !== null) { 389 409 $where[] = qsprintf( 390 410 $conn_r, 391 411 'audit.auditorPHID IN (%Ls)', ··· 458 478 $joins = array(); 459 479 $audit_request = new PhabricatorRepositoryAuditRequest(); 460 480 461 - if ($this->getAuditRequests()) { 481 + if ($this->shouldJoinAudits()) { 462 482 $joins[] = qsprintf( 463 483 $conn_r, 464 - 'JOIN %T audit ON commit.phid = audit.commitPHID', 484 + '%Q %T audit ON commit.phid = audit.commitPHID', 485 + ($this->rowsMustHaveAudits() ? 'JOIN' : 'LEFT JOIN'), 465 486 $audit_request->getTableName()); 466 487 } 467 488