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

Remove old reviewer double writes to legacy edge table in Differential

Summary:
Ref T2543. Ref T10967. This isn't precisely related to "draft" status, but while I'm churning this stuff anyway, get rid of the old double writes to clean the code up a bit.

These were added in T10967 to make sure the migration was reversible/recoverable, but we haven't seen any issues with it in several months so I believe they can now be removed safely. Nothing has read this table since ~April.

Test Plan: Took various review actions on revisions (accept, reject, resign, comment, etc). If this change is correct, there should be no visible effect.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10967, T2543

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

+3 -205
-141
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 257 257 258 258 $status_plan = ArcanistDifferentialRevisionStatus::CHANGES_PLANNED; 259 259 260 - $edge_reviewer = DifferentialRevisionHasReviewerEdgeType::EDGECONST; 261 260 $edge_ref_task = DifferentialRevisionHasTaskEdgeType::EDGECONST; 262 261 263 262 $is_sticky_accept = PhabricatorEnv::getEnvConfig( ··· 297 296 $old_accept = DifferentialReviewerStatus::STATUS_ACCEPTED_OLDER; 298 297 $old_reject = DifferentialReviewerStatus::STATUS_REJECTED_OLDER; 299 298 300 - if ($downgrade_rejects || $downgrade_accepts) { 301 - // When a revision is updated, change all "reject" to "rejected older 302 - // revision". This means we won't immediately push the update back into 303 - // "needs review", but outstanding rejects will still block it from 304 - // moving to "accepted". 305 - 306 - // We also do this for "Request Review", even though the diff is not 307 - // updated directly. Essentially, this acts like an update which doesn't 308 - // actually change the diff text. 309 - 310 - $edits = array(); 311 - foreach ($object->getReviewers() as $reviewer) { 312 - if ($downgrade_rejects) { 313 - if ($reviewer->getReviewerStatus() == $new_reject) { 314 - $edits[$reviewer->getReviewerPHID()] = array( 315 - 'data' => array( 316 - 'status' => $old_reject, 317 - ), 318 - ); 319 - } 320 - } 321 - 322 - if ($downgrade_accepts) { 323 - if ($reviewer->getReviewerStatus() == $new_accept) { 324 - $edits[$reviewer->getReviewerPHID()] = array( 325 - 'data' => array( 326 - 'status' => $old_accept, 327 - ), 328 - ); 329 - } 330 - } 331 - } 332 - 333 - if ($edits) { 334 - $results[] = id(new DifferentialTransaction()) 335 - ->setTransactionType($type_edge) 336 - ->setMetadataValue('edge:type', $edge_reviewer) 337 - ->setIgnoreOnNoEffect(true) 338 - ->setNewValue(array('+' => $edits)); 339 - } 340 - } 341 - 342 299 $downgrade = array(); 343 300 if ($downgrade_accepts) { 344 301 $downgrade[] = DifferentialReviewerStatus::STATUS_ACCEPTED; ··· 397 354 } 398 355 break; 399 356 400 - case PhabricatorTransactions::TYPE_COMMENT: 401 - // When a user leaves a comment, upgrade their reviewer status from 402 - // "added" to "commented" if they're also a reviewer. We may further 403 - // upgrade this based on other actions in the transaction group. 404 - 405 - if ($this->hasReviewTransaction) { 406 - // If we're also applying a review transaction, skip this. 407 - break; 408 - } 409 - 410 - $status_added = DifferentialReviewerStatus::STATUS_ADDED; 411 - $status_commented = DifferentialReviewerStatus::STATUS_COMMENTED; 412 - 413 - $data = array( 414 - 'status' => $status_commented, 415 - ); 416 - 417 - $edits = array(); 418 - foreach ($object->getReviewers() as $reviewer) { 419 - if ($reviewer->getReviewerPHID() == $actor_phid) { 420 - if ($reviewer->getReviewerStatus() == $status_added) { 421 - $edits[$actor_phid] = array( 422 - 'data' => $data, 423 - ); 424 - } 425 - } 426 - } 427 - 428 - if ($edits) { 429 - $results[] = id(new DifferentialTransaction()) 430 - ->setTransactionType($type_edge) 431 - ->setMetadataValue('edge:type', $edge_reviewer) 432 - ->setIgnoreOnNoEffect(true) 433 - ->setNewValue(array('+' => $edits)); 434 - } 435 - break; 436 - 437 357 case DifferentialRevisionCommandeerTransaction::TRANSACTIONTYPE: 438 358 $is_commandeer = true; 439 359 break; ··· 575 495 return parent::applyBuiltinExternalTransaction($object, $xaction); 576 496 } 577 497 578 - protected function mergeEdgeData($type, array $u, array $v) { 579 - $result = parent::mergeEdgeData($type, $u, $v); 580 - 581 - switch ($type) { 582 - case DifferentialRevisionHasReviewerEdgeType::EDGECONST: 583 - // When the same reviewer has their status updated by multiple 584 - // transactions, we want the strongest status to win. An example of 585 - // this is when a user adds a comment and also accepts a revision which 586 - // they are a reviewer on. The comment creates a "commented" status, 587 - // while the accept creates an "accepted" status. Since accept is 588 - // stronger, it should win and persist. 589 - 590 - $u_status = idx($u, 'status'); 591 - $v_status = idx($v, 'status'); 592 - $u_str = DifferentialReviewerStatus::getStatusStrength($u_status); 593 - $v_str = DifferentialReviewerStatus::getStatusStrength($v_status); 594 - if ($u_str > $v_str) { 595 - $result['status'] = $u_status; 596 - } else { 597 - $result['status'] = $v_status; 598 - } 599 - break; 600 - } 601 - 602 - return $result; 603 - } 604 - 605 498 protected function applyFinalEffects( 606 499 PhabricatorLiskDAO $object, 607 500 array $xactions) { ··· 748 641 749 642 foreach ($xactions as $xaction) { 750 643 switch ($type) { 751 - case PhabricatorTransactions::TYPE_EDGE: 752 - switch ($xaction->getMetadataValue('edge:type')) { 753 - case DifferentialRevisionHasReviewerEdgeType::EDGECONST: 754 - 755 - // Prevent the author from becoming a reviewer. 756 - 757 - // NOTE: This is pretty gross, but this restriction is unusual. 758 - // If we end up with too much more of this, we should try to clean 759 - // this up -- maybe by moving validation to after transactions 760 - // are adjusted (so we can just examine the final value) or adding 761 - // a second phase there? 762 - 763 - $author_phid = $object->getAuthorPHID(); 764 - $new = $xaction->getNewValue(); 765 - 766 - $add = idx($new, '+', array()); 767 - $eq = idx($new, '=', array()); 768 - $phids = array_keys($add + $eq); 769 - 770 - foreach ($phids as $phid) { 771 - if (($phid == $author_phid) && 772 - !$allow_self_accept && 773 - !$xaction->getIsCommandeerSideEffect()) { 774 - $errors[] = 775 - new PhabricatorApplicationTransactionValidationError( 776 - $type, 777 - pht('Invalid'), 778 - pht('The author of a revision can not be a reviewer.'), 779 - $xaction); 780 - } 781 - } 782 - break; 783 - } 784 - break; 785 644 case DifferentialTransaction::TYPE_UPDATE: 786 645 $diff = $this->loadDiff($xaction->getNewValue()); 787 646 if (!$diff) {
+1 -1
src/applications/differential/xaction/DifferentialRevisionAcceptTransaction.php
··· 103 103 if ($reviewer->isAccepted($diff_phid)) { 104 104 // If a reviewer is already in a full "accepted" state, don't 105 105 // include that reviewer as an option unless we're listing all 106 - // reviwers, including reviewers who have already accepted. 106 + // reviewers, including reviewers who have already accepted. 107 107 continue; 108 108 } 109 109 }
+2 -29
src/applications/differential/xaction/DifferentialRevisionReviewTransaction.php
··· 210 210 $map = array_select_keys($map, $value); 211 211 } 212 212 213 - // Convert reviewer statuses into edge data. 214 - foreach ($map as $reviewer_phid => $reviewer_status) { 215 - $map[$reviewer_phid] = array( 216 - 'data' => array( 217 - 'status' => $reviewer_status, 218 - ), 219 - ); 220 - } 221 - 222 - // This is currently double-writing: to the old (edge) store and the new 223 - // (reviewer) store. Do the old edge write first. 224 - 225 - $src_phid = $revision->getPHID(); 226 - $edge_type = DifferentialRevisionHasReviewerEdgeType::EDGECONST; 227 - 228 - $editor = new PhabricatorEdgeEditor(); 229 - foreach ($map as $dst_phid => $edge_data) { 230 - if ($status == DifferentialReviewerStatus::STATUS_RESIGNED) { 231 - // TODO: For now, we just remove these reviewers. In the future, we will 232 - // store resignations explicitly. 233 - $editor->removeEdge($src_phid, $edge_type, $dst_phid); 234 - } else { 235 - $editor->addEdge($src_phid, $edge_type, $dst_phid, $edge_data); 236 - } 237 - } 238 - 239 - $editor->save(); 240 - 241 213 // Now, do the new write. 242 214 243 215 if ($map) { ··· 249 221 } 250 222 251 223 $table = new DifferentialReviewer(); 224 + $src_phid = $revision->getPHID(); 252 225 253 226 $reviewers = $table->loadAllWhere( 254 227 'revisionPHID = %s AND reviewerPHID IN (%Ls)', ··· 256 229 array_keys($map)); 257 230 $reviewers = mpull($reviewers, null, 'getReviewerPHID'); 258 231 259 - foreach ($map as $dst_phid => $edge_data) { 232 + foreach (array_keys($map) as $dst_phid) { 260 233 $reviewer = idx($reviewers, $dst_phid); 261 234 if (!$reviewer) { 262 235 $reviewer = id(new DifferentialReviewer())
-34
src/applications/differential/xaction/DifferentialRevisionReviewersTransaction.php
··· 106 106 public function applyExternalEffects($object, $value) { 107 107 $src_phid = $object->getPHID(); 108 108 109 - // This is currently double-writing: to the old (edge) store and the new 110 - // (reviewer) store. Do the old edge write first. 111 - 112 109 $old = $this->generateOldValue($object); 113 110 $new = $value; 114 - $edge_type = DifferentialRevisionHasReviewerEdgeType::EDGECONST; 115 - 116 - $editor = new PhabricatorEdgeEditor(); 117 - 118 111 $rem = array_diff_key($old, $new); 119 - foreach ($rem as $dst_phid => $status) { 120 - $editor->removeEdge($src_phid, $edge_type, $dst_phid); 121 - } 122 - 123 - foreach ($new as $dst_phid => $status) { 124 - $old_status = idx($old, $dst_phid); 125 - if ($old_status === $status) { 126 - continue; 127 - } 128 - 129 - $data = array( 130 - 'data' => array( 131 - 'status' => $status, 132 - 133 - // TODO: This seemes like it's buggy before the Modular Transactions 134 - // changes. Figure out what's going on here? We don't have a very 135 - // clean way to get the active diff ID right now. 136 - 'diffID' => null, 137 - ), 138 - ); 139 - 140 - $editor->addEdge($src_phid, $edge_type, $dst_phid, $data); 141 - } 142 - 143 - $editor->save(); 144 - 145 - // Now, do the new write. 146 112 147 113 $table = new DifferentialReviewer(); 148 114 $table_name = $table->getTableName();