Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php
<?php | <?php | ||||
abstract class PhabricatorDiffInlineCommentQuery | abstract class PhabricatorDiffInlineCommentQuery | ||||
extends PhabricatorApplicationTransactionCommentQuery { | extends PhabricatorApplicationTransactionCommentQuery { | ||||
const INLINE_CONTEXT_CACHE_VERSION = 1; | |||||
private $fixedStates; | private $fixedStates; | ||||
private $needReplyToComments; | private $needReplyToComments; | ||||
private $publishedComments; | private $publishedComments; | ||||
private $publishableComments; | private $publishableComments; | ||||
private $needHidden; | private $needHidden; | ||||
private $needAppliedDrafts; | private $needAppliedDrafts; | ||||
private $needInlineContext; | private $needInlineContext; | ||||
abstract protected function buildInlineCommentWhereClauseParts( | abstract protected function buildInlineCommentWhereClauseParts( | ||||
AphrontDatabaseConnection $conn); | AphrontDatabaseConnection $conn); | ||||
abstract public function withObjectPHIDs(array $phids); | abstract public function withObjectPHIDs(array $phids); | ||||
abstract protected function loadHiddenCommentIDs( | abstract protected function loadHiddenCommentIDs( | ||||
$viewer_phid, | $viewer_phid, | ||||
array $comments); | array $comments); | ||||
abstract protected function newInlineContextMap(array $inlines); | abstract protected function newInlineContextMap(array $inlines); | ||||
abstract protected function newInlineContextFromCacheData(array $map); | |||||
final public function withFixedStates(array $states) { | final public function withFixedStates(array $states) { | ||||
$this->fixedStates = $states; | $this->fixedStates = $states; | ||||
return $this; | return $this; | ||||
} | } | ||||
final public function needReplyToComments($need_reply_to) { | final public function needReplyToComments($need_reply_to) { | ||||
$this->needReplyToComments = $need_reply_to; | $this->needReplyToComments = $need_reply_to; | ||||
▲ Show 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | if ($this->needInlineContext) { | ||||
$inline->attachInlineContext(null); | $inline->attachInlineContext(null); | ||||
continue; | continue; | ||||
} | } | ||||
$need_context[] = $inline; | $need_context[] = $inline; | ||||
} | } | ||||
if ($need_context) { | if ($need_context) { | ||||
$context_map = $this->newInlineContextMap($need_context); | $this->loadInlineCommentContext($need_context); | ||||
} | |||||
} | |||||
foreach ($need_context as $key => $inline) { | return $inlines; | ||||
$inline->attachInlineContext(idx($context_map, $key)); | |||||
} | } | ||||
private function loadInlineCommentContext(array $inlines) { | |||||
$cache_keys = array(); | |||||
foreach ($inlines as $key => $inline) { | |||||
$object = $inline->newInlineCommentObject(); | |||||
$fragment = $object->getInlineCommentCacheFragment(); | |||||
if ($fragment === null) { | |||||
continue; | |||||
} | } | ||||
$cache_keys[$key] = sprintf( | |||||
'%s.context(v%d)', | |||||
$fragment, | |||||
self::INLINE_CONTEXT_CACHE_VERSION); | |||||
} | } | ||||
return $inlines; | $cache = PhabricatorCaches::getMutableStructureCache(); | ||||
$cache_map = $cache->getKeys($cache_keys); | |||||
$context_map = array(); | |||||
$need_construct = array(); | |||||
foreach ($inlines as $key => $inline) { | |||||
$cache_key = idx($cache_keys, $key); | |||||
if ($cache_key !== null) { | |||||
if (array_key_exists($cache_key, $cache_map)) { | |||||
$cache_data = $cache_map[$cache_key]; | |||||
$context_map[$key] = $this->newInlineContextFromCacheData( | |||||
$cache_data); | |||||
continue; | |||||
} | |||||
} | |||||
$need_construct[$key] = $inline; | |||||
} | |||||
if ($need_construct) { | |||||
$construct_map = $this->newInlineContextMap($need_construct); | |||||
$write_map = array(); | |||||
foreach ($construct_map as $key => $context) { | |||||
if ($context === null) { | |||||
$cache_data = $context; | |||||
} else { | |||||
$cache_data = $this->newCacheDataFromInlineContext($context); | |||||
} | |||||
$cache_key = idx($cache_keys, $key); | |||||
if ($cache_key !== null) { | |||||
$write_map[$cache_key] = $cache_data; | |||||
} | |||||
} | |||||
if ($write_map) { | |||||
$cache->setKeys($write_map); | |||||
} | |||||
$context_map += $construct_map; | |||||
} | |||||
foreach ($inlines as $key => $inline) { | |||||
$inline->attachInlineContext(idx($context_map, $key)); | |||||
} | |||||
} | |||||
protected function newCacheDataFromInlineContext( | |||||
PhabricatorInlineCommentContext $context) { | |||||
return $context->newCacheDataMap(); | |||||
} | } | ||||
final protected function simplifyContext(array $lines, $is_head) { | final protected function simplifyContext(array $lines, $is_head) { | ||||
// We want to provide the smallest amount of context we can while still | // We want to provide the smallest amount of context we can while still | ||||
// being useful, since the actual code is visible nearby and showing a | // being useful, since the actual code is visible nearby and showing a | ||||
// ton of context is silly. | // ton of context is silly. | ||||
// Examine each line until we find one that looks "useful" (not just | // Examine each line until we find one that looks "useful" (not just | ||||
Show All 24 Lines |