From 1ea8bd3ab70560191462e8a1f03debfb7251be58 Mon Sep 17 00:00:00 2001 From: Nick Harper Date: Mon, 16 Apr 2012 12:35:48 -0700 Subject: [PATCH] Fix patch 131 for db with lots of revisions Summary: The old version of this loads all differential revisions at once, but that much can't all be loaded into memory when there are close to 500,000 revisions. This diff splits up loading the revisions. Test Plan: Ran this to run the migration in our install Reviewers: jungejason, epriestley Reviewed By: epriestley CC: aran Differential Revision: https://secure.phabricator.com/D2243 --- .../sql/patches/131.migraterevisionquery.php | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/resources/sql/patches/131.migraterevisionquery.php b/resources/sql/patches/131.migraterevisionquery.php index aacb1ea9df..2876047552 100644 --- a/resources/sql/patches/131.migraterevisionquery.php +++ b/resources/sql/patches/131.migraterevisionquery.php @@ -19,26 +19,29 @@ $table = new DifferentialRevision(); $conn_w = $table->establishConnection('w'); -$revisions = id(new DifferentialRevision())->loadAll(); +echo "Migrating revisions"; +do { + $revisions = id(new DifferentialRevision()) + ->loadAllWhere('branchName IS NULL LIMIT 1000'); -echo "Migrating ".count($revisions)." revisions"; -foreach ($revisions as $revision) { - echo "."; + foreach ($revisions as $revision) { + echo "."; - $diff = $revision->loadActiveDiff(); - if (!$diff) { - continue; + $diff = $revision->loadActiveDiff(); + if (!$diff) { + continue; + } + + $branch_name = $diff->getBranch(); + $arc_project_phid = $diff->getArcanistProjectPHID(); + + queryfx( + $conn_w, + 'UPDATE %T SET branchName = %s, arcanistProjectPHID = %s WHERE id = %d', + $table->getTableName(), + $branch_name, + $arc_project_phid, + $revision->getID()); } - - $branch_name = $diff->getBranch(); - $arc_project_phid = $diff->getArcanistProjectPHID(); - - queryfx( - $conn_w, - 'UPDATE %T SET branchName = %s, arcanistProjectPHID = %s WHERE id = %d', - $table->getTableName(), - $branch_name, - $arc_project_phid, - $revision->getID()); -} +} while (count($revisions) == 1000); echo "\nDone.\n";