Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F18854871
D9359.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D9359.id.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2045,6 +2045,7 @@
'PhabricatorRepositoryPHIDTypePushEvent' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypePushEvent.php',
'PhabricatorRepositoryPHIDTypePushLog' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypePushLog.php',
'PhabricatorRepositoryPHIDTypeRepository' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php',
+ 'PhabricatorRepositoryParentsWorker' => 'applications/repository/worker/PhabricatorRepositoryParentsWorker.php',
'PhabricatorRepositoryParsedChange' => 'applications/repository/data/PhabricatorRepositoryParsedChange.php',
'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php',
'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php',
@@ -4748,6 +4749,7 @@
2 => 'PhabricatorPolicyInterface',
3 => 'PhabricatorSubscribableInterface',
4 => 'PhabricatorCustomFieldInterface',
+ 5 => 'PhabricatorDestructableInterface',
),
'PhabricatorProjectArchiveController' => 'PhabricatorProjectController',
'PhabricatorProjectBoardController' => 'PhabricatorProjectController',
@@ -4758,6 +4760,7 @@
array(
0 => 'PhabricatorProjectDAO',
1 => 'PhabricatorPolicyInterface',
+ 2 => 'PhabricatorDestructableInterface',
),
'PhabricatorProjectColumnDetailController' => 'PhabricatorProjectBoardController',
'PhabricatorProjectColumnQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
@@ -4899,6 +4902,7 @@
'PhabricatorRepositoryPHIDTypePushEvent' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPHIDTypePushLog' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPHIDTypeRepository' => 'PhabricatorPHIDType',
+ 'PhabricatorRepositoryParentsWorker' => 'PhabricatorWorker',
'PhabricatorRepositoryParsedChange' => 'Phobject',
'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine',
'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon',
diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php
--- a/src/applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php
+++ b/src/applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php
@@ -14,8 +14,14 @@
->setArguments(
array(
array(
- 'name' => 'repos',
- 'wildcard' => true,
+ 'name' => 'background',
+ 'help' => 'Instead of executing in this process, queue tasks for '.
+ 'the daemons. This can improve performance, but makes '.
+ 'it more difficult to debug.',
+ ),
+ array(
+ 'name' => 'repos',
+ 'wildcard' => true,
),
));
}
@@ -28,6 +34,13 @@
->execute();
}
+ if ($args->getArg('background')) {
+ $is_background = true;
+ } else {
+ PhabricatorWorker::setRunAllTasksInProcess(true);
+ $is_background = false;
+ }
+
$console = PhutilConsole::getConsole();
foreach ($repos as $repo) {
$monogram = $repo->getMonogram();
@@ -40,13 +53,13 @@
$monogram));
continue;
}
- $this->rebuildRepository($repo);
+ $this->rebuildRepository($repo, $is_background);
}
return 0;
}
- private function rebuildRepository(PhabricatorRepository $repo) {
+ private function rebuildRepository(PhabricatorRepository $repo, $background) {
$console = PhutilConsole::getConsole();
$console->writeOut("%s\n", pht('Rebuilding "%s"...', $repo->getMonogram()));
@@ -87,70 +100,31 @@
}
}
- $console->writeOut(
- "%s\n",
- pht(
- 'Found %s total commit(s); updating...',
- new PhutilNumber(count($graph))));
-
- $commit_table = id(new PhabricatorRepositoryCommit());
- $commit_table_name = $commit_table->getTableName();
- $conn_w = $commit_table->establishConnection('w');
+ if ($background) {
+ $console->writeOut(
+ "%s\n",
+ pht(
+ 'Found %s total commit(s); queueing...',
+ new PhutilNumber(count($graph))));
+ } else {
+ $console->writeOut(
+ "%s\n",
+ pht(
+ 'Found %s total commit(s); updating...',
+ new PhutilNumber(count($graph))));
+ }
$bar = id(new PhutilConsoleProgressBar())
->setTotal(count($graph));
foreach ($graph as $child => $parents) {
- $names = $parents;
- $names[] = $child;
-
- $rows = queryfx_all(
- $conn_w,
- 'SELECT id, commitIdentifier FROM %T
- WHERE commitIdentifier IN (%Ls) AND repositoryID = %d',
- $commit_table_name,
- $names,
- $repo->getID());
-
- $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(
- $conn_w,
- '(%d, 0)',
- $map[$child]);
- } else {
- foreach ($parents as $parent) {
- $sql[] = qsprintf(
- $conn_w,
- '(%d, %d)',
- $map[$child],
- $map[$parent]);
- }
- }
-
- $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();
+ PhabricatorWorker::scheduleTask(
+ 'PhabricatorRepositoryParentsWorker',
+ array(
+ 'child' => $child,
+ 'parents' => $parents,
+ 'repo' => $repo->getID(),
+ ));
$bar->update(1);
}
diff --git a/src/applications/repository/worker/PhabricatorRepositoryParentsWorker.php b/src/applications/repository/worker/PhabricatorRepositoryParentsWorker.php
new file mode 100644
--- /dev/null
+++ b/src/applications/repository/worker/PhabricatorRepositoryParentsWorker.php
@@ -0,0 +1,67 @@
+<?php
+
+final class PhabricatorRepositoryParentsWorker extends PhabricatorWorker {
+
+ public function doWork() {
+ $commit_table = id(new PhabricatorRepositoryCommit());
+ $commit_table_name = $commit_table->getTableName();
+ $conn_w = $commit_table->establishConnection('w');
+
+ $data = $this->getTaskData();
+ $child = idx($data, 'child');
+ $parents = idx($data, 'parents');
+ $repo = idx($data, 'repo');
+
+ $names = $parents;
+ $names[] = $child;
+
+ $rows = queryfx_all(
+ $conn_w,
+ 'SELECT id, commitIdentifier FROM %T
+ WHERE commitIdentifier IN (%Ls) AND repositoryID = %d',
+ $commit_table_name,
+ $names,
+ $repo);
+
+ $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(
+ $conn_w,
+ '(%d, 0)',
+ $map[$child]);
+ } else {
+ foreach ($parents as $parent) {
+ $sql[] = qsprintf(
+ $conn_w,
+ '(%d, %d)',
+ $map[$child],
+ $map[$parent]);
+ }
+ }
+
+ $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();
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 2, 12:40 AM (1 d, 19 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
12258983
Default Alt Text
D9359.id.diff (8 KB)
Attached To
Mode
D9359: Add a `--background` option to the `./bin/repository parents` workflow.
Attached
Detach File
Event Timeline
Log In to Comment