Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/diffusion/query/pathchange/DiffusionPathChangeQuery.php b/src/applications/diffusion/query/pathchange/DiffusionPathChangeQuery.php
index 8ae9b3d203..850c06f105 100644
--- a/src/applications/diffusion/query/pathchange/DiffusionPathChangeQuery.php
+++ b/src/applications/diffusion/query/pathchange/DiffusionPathChangeQuery.php
@@ -1,116 +1,117 @@
<?php
final class DiffusionPathChangeQuery extends Phobject {
private $request;
private $limit;
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function getLimit() {
return $this->limit;
}
private function __construct() {
// <private>
}
public static function newFromDiffusionRequest(
DiffusionRequest $request) {
$query = new DiffusionPathChangeQuery();
$query->request = $request;
return $query;
}
protected function getRequest() {
return $this->request;
}
public function loadChanges() {
return $this->executeQuery();
}
protected function executeQuery() {
$drequest = $this->getRequest();
$repository = $drequest->getRepository();
$commit = $drequest->loadCommit();
$conn_r = $repository->establishConnection('r');
- $limit = '';
if ($this->limit) {
$limit = qsprintf(
$conn_r,
'LIMIT %d',
$this->limit + 1);
+ } else {
+ $limit = qsprintf($conn_r, '');
}
$raw_changes = queryfx_all(
$conn_r,
'SELECT c.*, p.path pathName, t.path targetPathName,
i.commitIdentifier targetCommitIdentifier
FROM %T c
LEFT JOIN %T p ON c.pathID = p.id
LEFT JOIN %T t ON c.targetPathID = t.id
LEFT JOIN %T i ON c.targetCommitID = i.id
WHERE c.commitID = %d AND isDirect = 1 %Q',
PhabricatorRepository::TABLE_PATHCHANGE,
PhabricatorRepository::TABLE_PATH,
PhabricatorRepository::TABLE_PATH,
$commit->getTableName(),
$commit->getID(),
$limit);
$limited = $this->limit && (count($raw_changes) > $this->limit);
if ($limited) {
$raw_changes = array_slice($raw_changes, 0, $this->limit);
}
$changes = array();
$raw_changes = isort($raw_changes, 'pathName');
foreach ($raw_changes as $raw_change) {
$type = $raw_change['changeType'];
if ($type == DifferentialChangeType::TYPE_CHILD) {
continue;
}
$change = new DiffusionPathChange();
$change->setPath(ltrim($raw_change['pathName'], '/'));
$change->setChangeType($raw_change['changeType']);
$change->setFileType($raw_change['fileType']);
$change->setCommitIdentifier($commit->getCommitIdentifier());
$change->setTargetPath(ltrim($raw_change['targetPathName'], '/'));
$change->setTargetCommitIdentifier($raw_change['targetCommitIdentifier']);
$id = $raw_change['pathID'];
$changes[$id] = $change;
}
// Deduce the away paths by examining all the changes, if we loaded them
// all.
if (!$limited) {
$away = array();
foreach ($changes as $change) {
if ($change->getTargetPath()) {
$away[$change->getTargetPath()][] = $change->getPath();
}
}
foreach ($changes as $change) {
if (isset($away[$change->getPath()])) {
$change->setAwayPaths($away[$change->getPath()]);
}
}
}
return $changes;
}
}
diff --git a/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php b/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php
index b544228561..f5d3af7fd8 100644
--- a/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php
+++ b/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php
@@ -1,160 +1,156 @@
<?php
abstract class PhabricatorRepositoryCommitChangeParserWorker
extends PhabricatorRepositoryCommitParserWorker {
protected function getImportStepFlag() {
return PhabricatorRepositoryCommit::IMPORTED_CHANGE;
}
public function getRequiredLeaseTime() {
// It can take a very long time to parse commits; some commits in the
// Facebook repository affect many millions of paths. Acquire 24h leases.
return phutil_units('24 hours in seconds');
}
abstract protected function parseCommitChanges(
PhabricatorRepository $repository,
PhabricatorRepositoryCommit $commit);
protected function parseCommit(
PhabricatorRepository $repository,
PhabricatorRepositoryCommit $commit) {
$this->log("%s\n", pht('Parsing "%s"...', $commit->getMonogram()));
$hint = $this->loadCommitHint($commit);
if ($hint && $hint->isUnreadable()) {
$this->log(
pht(
'This commit is marked as unreadable, so changes will not be '.
'parsed.'));
return;
}
if (!$this->shouldSkipImportStep()) {
$results = $this->parseCommitChanges($repository, $commit);
if ($results) {
$this->writeCommitChanges($repository, $commit, $results);
}
$commit->writeImportStatusFlag($this->getImportStepFlag());
PhabricatorSearchWorker::queueDocumentForIndexing($commit->getPHID());
}
$this->finishParse();
}
public function parseChangesForUnitTest(
PhabricatorRepository $repository,
PhabricatorRepositoryCommit $commit) {
return $this->parseCommitChanges($repository, $commit);
}
public static function lookupOrCreatePaths(array $paths) {
$repository = new PhabricatorRepository();
$conn_w = $repository->establishConnection('w');
$result_map = self::lookupPaths($paths);
$missing_paths = array_fill_keys($paths, true);
$missing_paths = array_diff_key($missing_paths, $result_map);
$missing_paths = array_keys($missing_paths);
if ($missing_paths) {
foreach (array_chunk($missing_paths, 128) as $path_chunk) {
$sql = array();
foreach ($path_chunk as $path) {
$sql[] = qsprintf($conn_w, '(%s, %s)', $path, md5($path));
}
queryfx(
$conn_w,
'INSERT IGNORE INTO %T (path, pathHash) VALUES %LQ',
PhabricatorRepository::TABLE_PATH,
$sql);
}
$result_map += self::lookupPaths($missing_paths);
}
return $result_map;
}
private static function lookupPaths(array $paths) {
$repository = new PhabricatorRepository();
$conn_w = $repository->establishConnection('w');
$result_map = array();
foreach (array_chunk($paths, 128) as $path_chunk) {
$chunk_map = queryfx_all(
$conn_w,
'SELECT path, id FROM %T WHERE pathHash IN (%Ls)',
PhabricatorRepository::TABLE_PATH,
array_map('md5', $path_chunk));
foreach ($chunk_map as $row) {
$result_map[$row['path']] = $row['id'];
}
}
return $result_map;
}
protected function finishParse() {
$commit = $this->commit;
if ($this->shouldQueueFollowupTasks()) {
$this->queueTask(
'PhabricatorRepositoryCommitOwnersWorker',
array(
'commitID' => $commit->getID(),
));
}
}
private function writeCommitChanges(
PhabricatorRepository $repository,
PhabricatorRepositoryCommit $commit,
array $changes) {
+ $conn = $repository->establishConnection('w');
+
$repository_id = (int)$repository->getID();
$commit_id = (int)$commit->getID();
- // NOTE: This SQL is being built manually instead of with qsprintf()
- // because some SVN changes affect an enormous number of paths (millions)
- // and this showed up as significantly slow on a profile at some point.
-
$changes_sql = array();
foreach ($changes as $change) {
- $values = array(
+ $changes_sql[] = qsprintf(
+ $conn,
+ '(%d, %d, %d, %nd, %nd, %d, %d, %d, %d)',
$repository_id,
(int)$change->getPathID(),
$commit_id,
- nonempty((int)$change->getTargetPathID(), 'null'),
- nonempty((int)$change->getTargetCommitID(), 'null'),
+ nonempty((int)$change->getTargetPathID(), null),
+ nonempty((int)$change->getTargetCommitID(), null),
(int)$change->getChangeType(),
(int)$change->getFileType(),
(int)$change->getIsDirect(),
- (int)$change->getCommitSequence(),
- );
- $changes_sql[] = '('.implode(', ', $values).')';
+ (int)$change->getCommitSequence());
}
- $conn_w = $repository->establishConnection('w');
-
queryfx(
- $conn_w,
+ $conn,
'DELETE FROM %T WHERE commitID = %d',
PhabricatorRepository::TABLE_PATHCHANGE,
$commit_id);
foreach (PhabricatorLiskDAO::chunkSQL($changes_sql) as $chunk) {
queryfx(
- $conn_w,
+ $conn,
'INSERT INTO %T
(repositoryID, pathID, commitID, targetPathID, targetCommitID,
changeType, fileType, isDirect, commitSequence)
VALUES %LQ',
PhabricatorRepository::TABLE_PATHCHANGE,
$chunk);
}
}
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jun 11, 12:53 AM (1 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
141531
Default Alt Text
(9 KB)

Event Timeline