@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 DifferentialRevisionQuery policy-aware

Summary:
Ref T603. Ref T2625. Makes `DifferentialRevisionQuery` do policy checks.

Note that it still uses inefficient offset-based paging, but it's rare to page through revisions. I'll switch to cursor paging in a future diff.

Test Plan: Viewed a bunch of Differential interfaces, home page, etc. This shouldn't actually materially impact anything.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603, T2625

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

+32 -86
+32 -86
src/applications/differential/query/DifferentialRevisionQuery.php
··· 12 12 * @task exec Query Execution 13 13 * @task internal Internals 14 14 */ 15 - final class DifferentialRevisionQuery { 15 + final class DifferentialRevisionQuery 16 + extends PhabricatorCursorPagedPolicyAwareQuery { 16 17 17 18 private $pathIDs = array(); 18 19 ··· 50 51 */ 51 52 const ORDER_PATH_MODIFIED = 'order-path-modified'; 52 53 53 - private $limit = 1000; 54 - private $offset = 0; 55 - 56 54 private $needRelationships = false; 57 55 private $needActiveDiffs = false; 58 56 private $needDiffIDs = false; 59 57 private $needCommitPHIDs = false; 60 58 private $needHashes = false; 61 - private $viewer; 62 - 63 - public function setViewer(PhabricatorUser $viewer) { 64 - $this->viewer = $viewer; 65 - return $this; 66 - } 67 - 68 - public function getViewer() { 69 - return $this->viewer; 70 - } 71 59 72 60 73 61 /* -( Query Configuration )------------------------------------------------ */ ··· 268 256 269 257 270 258 /** 271 - * Set result limit. If unspecified, defaults to 1000. 272 - * 273 - * @param int Result limit. 274 - * @return this 275 - * @task config 276 - */ 277 - public function setLimit($limit) { 278 - $this->limit = $limit; 279 - return $this; 280 - } 281 - 282 - 283 - /** 284 - * Set result offset. If unspecified, defaults to 0. 285 - * 286 - * @param int Result offset. 287 - * @return this 288 - * @task config 289 - */ 290 - public function setOffset($offset) { 291 - $this->offset = $offset; 292 - return $this; 293 - } 294 - 295 - 296 - /** 297 259 * Set whether or not the query will load and attach relationships. 298 260 * 299 261 * @param bool True to load and attach relationships. ··· 372 334 * @return list List of matching DifferentialRevision objects. 373 335 * @task exec 374 336 */ 375 - public function execute() { 337 + public function loadPage() { 376 338 $table = new DifferentialRevision(); 377 339 $conn_r = $table->establishConnection('r'); 378 340 379 341 $data = $this->loadData(); 380 342 381 - $revisions = $table->loadAllFromArray($data); 343 + return $table->loadAllFromArray($data); 344 + } 382 345 383 - if ($revisions) { 384 - if ($this->needRelationships) { 385 - $this->loadRelationships($conn_r, $revisions); 386 - } 346 + public function willFilterPage(array $revisions) { 347 + if (!$revisions) { 348 + return $revisions; 349 + } 387 350 388 - if ($this->needCommitPHIDs) { 389 - $this->loadCommitPHIDs($conn_r, $revisions); 390 - } 351 + $table = new DifferentialRevision(); 352 + $conn_r = $table->establishConnection('r'); 391 353 392 - $need_active = $this->needActiveDiffs; 393 - $need_ids = $need_active || 394 - $this->needDiffIDs; 354 + if ($this->needRelationships) { 355 + $this->loadRelationships($conn_r, $revisions); 356 + } 395 357 396 - if ($need_ids) { 397 - $this->loadDiffIDs($conn_r, $revisions); 398 - } 358 + if ($this->needCommitPHIDs) { 359 + $this->loadCommitPHIDs($conn_r, $revisions); 360 + } 361 + 362 + $need_active = $this->needActiveDiffs; 363 + $need_ids = $need_active || $this->needDiffIDs; 364 + 365 + if ($need_ids) { 366 + $this->loadDiffIDs($conn_r, $revisions); 367 + } 399 368 400 - if ($need_active) { 401 - $this->loadActiveDiffs($conn_r, $revisions); 402 - } 369 + if ($need_active) { 370 + $this->loadActiveDiffs($conn_r, $revisions); 371 + } 403 372 404 - if ($this->needHashes) { 405 - $this->loadHashes($conn_r, $revisions); 406 - } 373 + if ($this->needHashes) { 374 + $this->loadHashes($conn_r, $revisions); 407 375 } 408 376 409 377 return $revisions; 410 - } 411 - 412 - public function executeOne() { 413 - return head($this->execute()); 414 378 } 415 379 416 380 private function loadData() { ··· 513 477 $limit); 514 478 } 515 479 516 - private function buildLimitClause(AphrontDatabaseConnection $conn_r) { 517 - $limit = ''; 518 - if ($this->offset || $this->limit) { 519 - $limit = qsprintf( 520 - $conn_r, 521 - 'LIMIT %d, %d', 522 - (int)$this->offset, 523 - $this->limit); 524 - } 525 - 526 - return $limit; 527 - } 528 480 529 481 /* -( Internals )---------------------------------------------------------- */ 530 482 ··· 723 675 "Unknown revision status filter constant '{$this->status}'!"); 724 676 } 725 677 726 - if ($where) { 727 - $where = 'WHERE '.implode(' AND ', $where); 728 - } else { 729 - $where = ''; 730 - } 731 - 732 - return $where; 678 + $where[] = $this->buildPagingCLause($conn_r); 679 + return $this->formatWhereClause($where); 733 680 } 734 681 735 682 ··· 741 688 $this->pathIDs, 742 689 $this->ccs, 743 690 $this->reviewers, 744 - $this->subscribers, 745 - $this->responsibles); 691 + $this->subscribers); 746 692 747 693 $needs_distinct = (count($join_triggers) > 1); 748 694