1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-25 14:08:19 +01:00

(stable) Promote 2018 Week 42

This commit is contained in:
epriestley 2018-10-20 03:47:31 -07:00
commit 9c514bcf93
5 changed files with 99 additions and 11 deletions

View file

@ -88,6 +88,20 @@ final class DifferentialChangesetEngine extends Phobject {
private function detectCopiedCode(array $changesets) { private function detectCopiedCode(array $changesets) {
// See PHI944. If the total number of changed lines is excessively large,
// don't bother with copied code detection. This can take a lot of time and
// memory and it's not generally of any use for very large changes.
$max_size = 65535;
$total_size = 0;
foreach ($changesets as $changeset) {
$total_size += ($changeset->getAddLines() + $changeset->getDelLines());
}
if ($total_size > $max_size) {
return;
}
$min_width = 30; $min_width = 30;
$min_lines = 3; $min_lines = 3;

View file

@ -688,6 +688,9 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
'fetchable.')); 'fetchable.'));
} }
// If we can synchronize from multiple sources, choose one at random.
shuffle($fetchable);
$caught = null; $caught = null;
foreach ($fetchable as $binding) { foreach ($fetchable as $binding) {
try { try {

View file

@ -23,6 +23,7 @@ final class PhabricatorMetaMTAMailableFunctionDatasource
new PhabricatorProjectMembersDatasource(), new PhabricatorProjectMembersDatasource(),
new PhabricatorProjectDatasource(), new PhabricatorProjectDatasource(),
new PhabricatorOwnersPackageDatasource(), new PhabricatorOwnersPackageDatasource(),
new PhabricatorOwnersPackageOwnerDatasource(),
); );
} }

View file

@ -27,7 +27,7 @@ final class PhabricatorOwnersPackageOwnerDatasource
'packages' => array( 'packages' => array(
'name' => pht('Packages: ...'), 'name' => pht('Packages: ...'),
'arguments' => pht('owner'), 'arguments' => pht('owner'),
'summary' => pht("Find results in any of an owner's projects."), 'summary' => pht("Find results in any of an owner's packages."),
'description' => pht( 'description' => pht(
"This function allows you to find results associated with any ". "This function allows you to find results associated with any ".
"of the packages a specified user or project is an owner of. ". "of the packages a specified user or project is an owner of. ".
@ -61,18 +61,21 @@ final class PhabricatorOwnersPackageOwnerDatasource
$phids = $this->resolvePHIDs($phids); $phids = $this->resolvePHIDs($phids);
$user_phids = array(); $owner_phids = array();
foreach ($phids as $key => $phid) { foreach ($phids as $key => $phid) {
if (phid_get_type($phid) == PhabricatorPeopleUserPHIDType::TYPECONST) { switch (phid_get_type($phid)) {
$user_phids[] = $phid; case PhabricatorPeopleUserPHIDType::TYPECONST:
unset($phids[$key]); case PhabricatorProjectProjectPHIDType::TYPECONST:
$owner_phids[] = $phid;
unset($phids[$key]);
break;
} }
} }
if ($user_phids) { if ($owner_phids) {
$packages = id(new PhabricatorOwnersPackageQuery()) $packages = id(new PhabricatorOwnersPackageQuery())
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
->withOwnerPHIDs($user_phids) ->withOwnerPHIDs($owner_phids)
->execute(); ->execute();
foreach ($packages as $package) { foreach ($packages as $package) {
$phids[] = $package->getPHID(); $phids[] = $package->getPHID();
@ -116,8 +119,13 @@ final class PhabricatorOwnersPackageOwnerDatasource
$usernames = array(); $usernames = array();
foreach ($phids as $key => $phid) { foreach ($phids as $key => $phid) {
if (phid_get_type($phid) != PhabricatorPeopleUserPHIDType::TYPECONST) { switch (phid_get_type($phid)) {
$usernames[$key] = $phid; case PhabricatorPeopleUserPHIDType::TYPECONST:
case PhabricatorProjectProjectPHIDType::TYPECONST:
break;
default:
$usernames[$key] = $phid;
break;
} }
} }

View file

@ -2010,12 +2010,72 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
} }
} }
shuffle($results); if ($writable) {
$results = $this->sortWritableAlmanacServiceURIs($results);
} else {
shuffle($results);
}
$result = head($results); $result = head($results);
return $result['uri']; return $result['uri'];
} }
private function sortWritableAlmanacServiceURIs(array $results) {
// See T13109 for discussion of how this method routes requests.
// In the absence of other rules, we'll send traffic to devices randomly.
// We also want to select randomly among nodes which are equally good
// candidates to receive the write, and accomplish that by shuffling the
// list up front.
shuffle($results);
$order = array();
// If some device is currently holding the write lock, send all requests
// to that device. We're trying to queue writes on a single device so they
// do not need to wait for read synchronization after earlier writes
// complete.
$writer = PhabricatorRepositoryWorkingCopyVersion::loadWriter(
$this->getPHID());
if ($writer) {
$device_phid = $writer->getWriteProperty('devicePHID');
foreach ($results as $key => $result) {
if ($result['devicePHID'] === $device_phid) {
$order[] = $key;
}
}
}
// If no device is currently holding the write lock, try to send requests
// to a device which is already up to date and will not need to synchronize
// before it can accept the write.
$versions = PhabricatorRepositoryWorkingCopyVersion::loadVersions(
$this->getPHID());
if ($versions) {
$max_version = (int)max(mpull($versions, 'getRepositoryVersion'));
$max_devices = array();
foreach ($versions as $version) {
if ($version->getRepositoryVersion() == $max_version) {
$max_devices[] = $version->getDevicePHID();
}
}
$max_devices = array_fuse($max_devices);
foreach ($results as $key => $result) {
if (isset($max_devices[$result['devicePHID']])) {
$order[] = $key;
}
}
}
// Reorder the results, putting any we've selected as preferred targets for
// the write at the head of the list.
$results = array_select_keys($results, $order) + $results;
return $results;
}
public function supportsSynchronization() { public function supportsSynchronization() {
// TODO: For now, this is only supported for Git. // TODO: For now, this is only supported for Git.
if (!$this->isGit()) { if (!$this->isGit()) {
@ -2036,7 +2096,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$parts = array( $parts = array(
"repo({$repository_phid})", "repo({$repository_phid})",
"serv({$service_phid})", "serv({$service_phid})",
'v2', 'v3',
); );
return implode('.', $parts); return implode('.', $parts);
@ -2063,12 +2123,14 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$uri = $this->getClusterRepositoryURIFromBinding($binding); $uri = $this->getClusterRepositoryURIFromBinding($binding);
$protocol = $uri->getProtocol(); $protocol = $uri->getProtocol();
$device_name = $iface->getDevice()->getName(); $device_name = $iface->getDevice()->getName();
$device_phid = $iface->getDevice()->getPHID();
$uris[] = array( $uris[] = array(
'protocol' => $protocol, 'protocol' => $protocol,
'uri' => (string)$uri, 'uri' => (string)$uri,
'device' => $device_name, 'device' => $device_name,
'writable' => (bool)$binding->getAlmanacPropertyValue('writable'), 'writable' => (bool)$binding->getAlmanacPropertyValue('writable'),
'devicePHID' => $device_phid,
); );
} }