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

Render shields before highlighting code

Summary:
It saves some time on non-highlighting generated and other not interesting code.

The code is quite complex (300 lines methods) so I'm not sure if everything is moved correctly.

P.S. I hope that moved code detector will work...

Test Plan:
Display generated file with all whitespace, verify that it is not highlighted.
Display normal file.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin

Maniphest Tasks: T1134

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

vrana 3fa310f3 8745374c

+75 -66
+75 -66
src/applications/differential/parser/changeset/DifferentialChangesetParser.php
··· 486 486 } 487 487 } 488 488 489 - // NOTE: Micro-optimize a couple of ipull()s here since it gives us a 490 - // 10% performance improvement for certain types of large diffs like 491 - // Phriction changes. 492 - 493 489 $old_corpus = array(); 494 490 foreach ($this->old as $o) { 495 491 if ($o['type'] != '\\') { ··· 506 502 } 507 503 $new_corpus_block = implode("\n", $new_corpus); 508 504 505 + $generated_guess = (strpos($new_corpus_block, '@'.'generated') !== false); 506 + 507 + if (!$generated_guess) { 508 + $config_key = 'differential.generated-paths'; 509 + $generated_path_regexps = PhabricatorEnv::getEnvConfig($config_key); 510 + foreach ($generated_path_regexps as $regexp) { 511 + if (preg_match($regexp, $this->changeset->getFilename())) { 512 + $generated_guess = true; 513 + break; 514 + } 515 + } 516 + } 517 + 518 + $event = new PhabricatorEvent( 519 + PhabricatorEventType::TYPE_DIFFERENTIAL_WILLMARKGENERATED, 520 + array( 521 + 'corpus' => $new_corpus_block, 522 + 'is_generated' => $generated_guess 523 + ) 524 + ); 525 + PhutilEventEngine::dispatchEvent($event); 526 + 527 + $generated = $event->getValue('is_generated'); 528 + $this->specialAttributes[self::ATTR_GENERATED] = $generated; 529 + 530 + if ($this->isTopLevel && !$this->comments && 531 + ($this->isGenerated() || $this->isUnchanged() || $this->isDeleted())) { 532 + return; 533 + } 534 + 509 535 $old_future = $this->getHighlightFuture($old_corpus_block); 510 536 $new_future = $this->getHighlightFuture($new_corpus_block); 511 537 $futures = array( ··· 553 579 $this->newRender, 554 580 ipull($this->intra, 1), 555 581 $new_corpus); 556 - 557 - $generated_guess = (strpos($new_corpus_block, '@'.'generated') !== false); 558 - 559 - if (!$generated_guess) { 560 - $config_key = 'differential.generated-paths'; 561 - $generated_path_regexps = PhabricatorEnv::getEnvConfig($config_key); 562 - foreach ($generated_path_regexps as $regexp) { 563 - if (preg_match($regexp, $this->changeset->getFilename())) { 564 - $generated_guess = true; 565 - break; 566 - } 567 - } 568 - } 569 - 570 - $event = new PhabricatorEvent( 571 - PhabricatorEventType::TYPE_DIFFERENTIAL_WILLMARKGENERATED, 572 - array( 573 - 'corpus' => $new_corpus_block, 574 - 'is_generated' => $generated_guess 575 - ) 576 - ); 577 - PhutilEventEngine::dispatchEvent($event); 578 - 579 - $generated = $event->getValue('is_generated'); 580 - 581 - $this->specialAttributes[self::ATTR_GENERATED] = $generated; 582 582 } 583 583 584 584 public function loadCache() { ··· 615 615 } 616 616 617 617 if ($data['cacheVersion'] !== self::CACHE_VERSION) { 618 + return false; 619 + } 620 + 621 + // Someone displays contents of a partially cached shielded file. 622 + if (!isset($data['newRender']) && (!$this->isTopLevel || $this->comments)) { 618 623 return false; 619 624 } 620 625 ··· 862 867 // requests. 863 868 $this->isTopLevel = (($range_start === null) && ($range_len === null)); 864 869 870 + $this->highlightEngine = PhabricatorSyntaxHighlighter::newEngine(); 865 871 866 - $this->highlightEngine = PhabricatorSyntaxHighlighter::newEngine(); 872 + $shield = null; 873 + if ($this->isTopLevel && !$this->comments && 874 + !($this->isGenerated() || $this->isUnchanged() || $this->isDeleted()) && 875 + $this->changeset->getAffectedLineCount() > 2500) { 876 + $lines = number_format($this->changeset->getAffectedLineCount()); 877 + $shield = $this->renderShield( 878 + "This file has a very large number of changes ({$lines} lines).", 879 + true); 880 + } else { 881 + 882 + $this->tryCacheStuff(); 867 883 868 - $this->tryCacheStuff(); 884 + if ($this->isTopLevel && !$this->comments) { 885 + if ($this->isGenerated()) { 886 + $shield = $this->renderShield( 887 + "This file contains generated code, which does not normally need ". 888 + "to be reviewed.", 889 + true); 890 + } else if ($this->isUnchanged()) { 891 + if ($this->isWhitespaceOnly()) { 892 + $shield = $this->renderShield( 893 + "This file was changed only by adding or removing trailing ". 894 + "whitespace.", 895 + false); 896 + } else { 897 + $shield = $this->renderShield( 898 + "The contents of this file were not changed.", 899 + false); 900 + } 901 + } else if ($this->isDeleted()) { 902 + $shield = $this->renderShield( 903 + "This file was completely deleted.", 904 + true); 905 + } 906 + } 907 + } 908 + 909 + if ($shield) { 910 + return $this->renderChangesetTable($this->changeset, $shield); 911 + } 869 912 870 913 $feedback_mask = array(); 871 914 ··· 1002 1045 case DifferentialChangeType::FILE_BINARY: 1003 1046 $output = $this->renderChangesetTable($this->changeset, null); 1004 1047 return $output; 1005 - } 1006 - 1007 - $shield = null; 1008 - if ($this->isTopLevel && !$this->comments) { 1009 - if ($this->isGenerated()) { 1010 - $shield = $this->renderShield( 1011 - "This file contains generated code, which does not normally need ". 1012 - "to be reviewed.", 1013 - true); 1014 - } else if ($this->isUnchanged()) { 1015 - if ($this->isWhitespaceOnly()) { 1016 - $shield = $this->renderShield( 1017 - "This file was changed only by adding or removing trailing ". 1018 - "whitespace.", 1019 - false); 1020 - } else { 1021 - $shield = $this->renderShield( 1022 - "The contents of this file were not changed.", 1023 - false); 1024 - } 1025 - } else if ($this->isDeleted()) { 1026 - $shield = $this->renderShield( 1027 - "This file was completely deleted.", 1028 - true); 1029 - } else if ($this->changeset->getAffectedLineCount() > 2500) { 1030 - $lines = number_format($this->changeset->getAffectedLineCount()); 1031 - $shield = $this->renderShield( 1032 - "This file has a very large number of changes ({$lines} lines).", 1033 - true); 1034 - } 1035 - } 1036 - 1037 - if ($shield) { 1038 - return $this->renderChangesetTable($this->changeset, $shield); 1039 1048 } 1040 1049 1041 1050 $old_comments = array();