mirror of
https://we.phorge.it/source/phorge.git
synced 2025-04-11 03:48:34 +02:00
Summary: Ref T11404. Depends on D16351. Currently, both `differential.query` and `differential.revision.search` issue `2N` queries to fetch: - dependencies for each revision; and - projects for each revision. Fix this: - Take these custom fields out of Conduit so they don't load this data by default. - For `differential.query`, put this data back in by hard coding it. - For `differential.revision.search`, just leave it out. You can already optionally get projects efficiently, and this endpoint is a work in progress. I would tentatively be inclined to expose graph data as a "graph" extension once we need it. This makes both methods execute in `O(1)` time (which is still 20-30 queries, but at least it's not 320 queries anymore). Test Plan: - Ran `differential.query`, observed no change in results but 199 fewer internal queries. - Ran `differential.revision.search`, observed data gone from results and 200 fewer internal queries. Reviewers: yelirekim, chad Reviewed By: chad Maniphest Tasks: T11404 Differential Revision: https://secure.phabricator.com/D16352
114 lines
2.7 KiB
PHP
114 lines
2.7 KiB
PHP
<?php
|
|
|
|
final class DifferentialProjectsField
|
|
extends DifferentialCoreCustomField {
|
|
|
|
public function getFieldKey() {
|
|
return 'phabricator:projects';
|
|
}
|
|
|
|
public function getFieldName() {
|
|
return pht('Tags');
|
|
}
|
|
|
|
public function getFieldDescription() {
|
|
return pht('Tag projects.');
|
|
}
|
|
|
|
public function shouldAppearInPropertyView() {
|
|
return false;
|
|
}
|
|
|
|
public function shouldAppearInEditView() {
|
|
return true;
|
|
}
|
|
|
|
public function shouldAppearInApplicationTransactions() {
|
|
return true;
|
|
}
|
|
|
|
protected function readValueFromRevision(
|
|
DifferentialRevision $revision) {
|
|
if (!$revision->getPHID()) {
|
|
return array();
|
|
}
|
|
|
|
$projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
$revision->getPHID(),
|
|
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
|
|
$projects = array_reverse($projects);
|
|
|
|
return $projects;
|
|
}
|
|
|
|
public function getNewValueForApplicationTransactions() {
|
|
return array('=' => array_fuse($this->getValue()));
|
|
}
|
|
|
|
public function readValueFromRequest(AphrontRequest $request) {
|
|
$this->setValue($request->getArr($this->getFieldKey()));
|
|
}
|
|
|
|
public function renderEditControl(array $handles) {
|
|
return id(new AphrontFormTokenizerControl())
|
|
->setUser($this->getViewer())
|
|
->setName($this->getFieldKey())
|
|
->setDatasource(new PhabricatorProjectDatasource())
|
|
->setValue($this->getValue())
|
|
->setLabel($this->getFieldName());
|
|
}
|
|
|
|
public function getApplicationTransactionType() {
|
|
return PhabricatorTransactions::TYPE_EDGE;
|
|
}
|
|
|
|
public function shouldAppearInCommitMessage() {
|
|
return true;
|
|
}
|
|
|
|
public function shouldAllowEditInCommitMessage() {
|
|
return true;
|
|
}
|
|
|
|
public function shouldOverwriteWhenCommitMessageIsEdited() {
|
|
return true;
|
|
}
|
|
|
|
public function getCommitMessageLabels() {
|
|
return array(
|
|
'Tags',
|
|
'Project',
|
|
'Projects',
|
|
);
|
|
}
|
|
|
|
public function getRequiredHandlePHIDsForCommitMessage() {
|
|
return $this->getValue();
|
|
}
|
|
|
|
public function renderCommitMessageValue(array $handles) {
|
|
return $this->renderObjectList($handles);
|
|
}
|
|
|
|
public function shouldAppearInConduitDictionary() {
|
|
// To improve performance, we exclude this field from Conduit results.
|
|
// See T11404 for discussion. In modern "differential.revision.search",
|
|
// this information is available efficiently as an attachment.
|
|
return false;
|
|
}
|
|
|
|
public function getApplicationTransactionMetadata() {
|
|
return array(
|
|
'edge:type' => PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
|
|
);
|
|
}
|
|
|
|
public function parseValueFromCommitMessage($value) {
|
|
return $this->parseObjectList(
|
|
$value,
|
|
array(
|
|
PhabricatorProjectProjectPHIDType::TYPECONST,
|
|
));
|
|
}
|
|
|
|
}
|