1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Batch up SQL operations in the ./bin/repository parents script.

Summary: Fixes T5255. Currently the `./bin/repository parents` workflow is quite slow. Batching up the SQL operations should make the workflow //seem// much faster.

Test Plan: Not yet tested.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T5255

Differential Revision: https://secure.phabricator.com/D9361
This commit is contained in:
Joshua Spence 2014-06-03 11:27:57 -07:00 committed by epriestley
parent e3d7c16d8c
commit 1503840cd9

View file

@ -100,35 +100,50 @@ final class PhabricatorRepositoryManagementParentsWorkflow
$bar = id(new PhutilConsoleProgressBar()) $bar = id(new PhutilConsoleProgressBar())
->setTotal(count($graph)); ->setTotal(count($graph));
$need = array();
foreach ($graph as $child => $parents) { foreach ($graph as $child => $parents) {
$names = $parents; foreach ($parents as $parent) {
$names[] = $child; $need[$parent] = $parent;
}
$need[$child] = $child;
}
$map = array();
foreach (array_chunk($need, 2048) as $chunk) {
$rows = queryfx_all( $rows = queryfx_all(
$conn_w, $conn_w,
'SELECT id, commitIdentifier FROM %T 'SELECT id, commitIdentifier FROM %T
WHERE commitIdentifier IN (%Ls) AND repositoryID = %d', WHERE commitIdentifier IN (%Ls) AND repositoryID = %d',
$commit_table_name, $commit_table_name,
$names, $chunk,
$repo->getID()); $repo->getID());
foreach ($rows as $row) {
$map[$row['commitIdentifier']] = $row['id'];
}
}
$insert_sql = array();
$delete_sql = array();
foreach ($graph as $child => $parents) {
$names = $parents;
$names[] = $child;
$map = ipull($rows, 'id', 'commitIdentifier');
foreach ($names as $name) { foreach ($names as $name) {
if (empty($map[$name])) { if (empty($map[$name])) {
throw new Exception(pht('Unknown commit "%s"!', $name)); throw new Exception(pht('Unknown commit "%s"!', $name));
} }
} }
$sql = array();
if (!$parents) { if (!$parents) {
// Write an explicit 0 to indicate "no parents" instead of "no data". // Write an explicit 0 to indicate "no parents" instead of "no data".
$sql[] = qsprintf( $insert_sql[] = qsprintf(
$conn_w, $conn_w,
'(%d, 0)', '(%d, 0)',
$map[$child]); $map[$child]);
} else { } else {
foreach ($parents as $parent) { foreach ($parents as $parent) {
$sql[] = qsprintf( $insert_sql[] = qsprintf(
$conn_w, $conn_w,
'(%d, %d)', '(%d, %d)',
$map[$child], $map[$child],
@ -136,25 +151,29 @@ final class PhabricatorRepositoryManagementParentsWorkflow
} }
} }
$commit_table->openTransaction(); $delete_sql[] = $map[$child];
queryfx(
$conn_w,
'DELETE FROM %T WHERE childCommitID = %d',
PhabricatorRepository::TABLE_PARENTS,
$map[$child]);
if ($sql) {
queryfx(
$conn_w,
'INSERT INTO %T (childCommitID, parentCommitID) VALUES %Q',
PhabricatorRepository::TABLE_PARENTS,
implode(', ', $sql));
}
$commit_table->saveTransaction();
$bar->update(1); $bar->update(1);
} }
$commit_table->openTransaction();
foreach (PhabricatorLiskDAO::chunkSQL($delete_sql) as $chunk) {
queryfx(
$conn_w,
'DELETE FROM %T WHERE childCommitID IN (%Q)',
PhabricatorRepository::TABLE_PARENTS,
$chunk);
}
foreach (PhabricatorLiskDAO::chunkSQL($insert_sql) as $chunk) {
queryfx(
$conn_w,
'INSERT INTO %T (childCommitID, parentCommitID) VALUES %Q',
PhabricatorRepository::TABLE_PARENTS,
$chunk);
}
$commit_table->saveTransaction();
$bar->done(); $bar->done();
} }