mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +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:
parent
e3d7c16d8c
commit
1503840cd9
1 changed files with 41 additions and 22 deletions
|
@ -100,35 +100,50 @@ final class PhabricatorRepositoryManagementParentsWorkflow
|
|||
$bar = id(new PhutilConsoleProgressBar())
|
||||
->setTotal(count($graph));
|
||||
|
||||
$need = array();
|
||||
foreach ($graph as $child => $parents) {
|
||||
$names = $parents;
|
||||
$names[] = $child;
|
||||
foreach ($parents as $parent) {
|
||||
$need[$parent] = $parent;
|
||||
}
|
||||
$need[$child] = $child;
|
||||
}
|
||||
|
||||
$map = array();
|
||||
foreach (array_chunk($need, 2048) as $chunk) {
|
||||
$rows = queryfx_all(
|
||||
$conn_w,
|
||||
'SELECT id, commitIdentifier FROM %T
|
||||
WHERE commitIdentifier IN (%Ls) AND repositoryID = %d',
|
||||
$commit_table_name,
|
||||
$names,
|
||||
$chunk,
|
||||
$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) {
|
||||
if (empty($map[$name])) {
|
||||
throw new Exception(pht('Unknown commit "%s"!', $name));
|
||||
}
|
||||
}
|
||||
|
||||
$sql = array();
|
||||
if (!$parents) {
|
||||
// Write an explicit 0 to indicate "no parents" instead of "no data".
|
||||
$sql[] = qsprintf(
|
||||
$insert_sql[] = qsprintf(
|
||||
$conn_w,
|
||||
'(%d, 0)',
|
||||
$map[$child]);
|
||||
} else {
|
||||
foreach ($parents as $parent) {
|
||||
$sql[] = qsprintf(
|
||||
$insert_sql[] = qsprintf(
|
||||
$conn_w,
|
||||
'(%d, %d)',
|
||||
$map[$child],
|
||||
|
@ -136,25 +151,29 @@ final class PhabricatorRepositoryManagementParentsWorkflow
|
|||
}
|
||||
}
|
||||
|
||||
$commit_table->openTransaction();
|
||||
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();
|
||||
$delete_sql[] = $map[$child];
|
||||
|
||||
$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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue