Making upgrade.php somewhat more efficient by remember one-time-inits.

This commit is contained in:
Mikael Nordfeldth 2017-07-10 19:39:26 +02:00
parent c9cfda5ef2
commit 6a2a54dcb5

View File

@ -20,8 +20,8 @@
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$shortoptions = 'x::'; $shortoptions = 'dfx::';
$longoptions = array('extensions='); $longoptions = array('debug', 'files', 'extensions=');
$helptext = <<<END_OF_UPGRADE_HELP $helptext = <<<END_OF_UPGRADE_HELP
php upgrade.php [options] php upgrade.php [options]
@ -31,8 +31,17 @@ END_OF_UPGRADE_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc'; require_once INSTALLDIR.'/scripts/commandline.inc';
if (!defined('DEBUG')) {
define('DEBUG', (bool)have_option('d', 'debug'));
}
function main() function main()
{ {
// "files" option enables possibly disk/resource intensive operations
// that aren't really _required_ for the upgrade
$iterate_files = (bool)have_option('f', 'files');
if (Event::handle('StartUpgrade')) { if (Event::handle('StartUpgrade')) {
fixupConversationURIs(); fixupConversationURIs();
@ -44,11 +53,17 @@ function main()
fixupNoticeConversation(); fixupNoticeConversation();
initConversation(); initConversation();
fixupGroupURI(); fixupGroupURI();
fixupFileGeometry(); if ($iterate_files) {
deleteLocalFileThumbnailsWithoutFilename(); printfnq("Running file iterations:\n");
deleteMissingLocalFileThumbnails(); printfnq("* "); fixupFileGeometry();
fixupFileThumbnailUrlhash(); printfnq("* "); deleteLocalFileThumbnailsWithoutFilename();
setFilehashOnLocalFiles(); printfnq("* "); deleteMissingLocalFileThumbnails();
printfnq("* "); fixupFileThumbnailUrlhash();
printfnq("* "); setFilehashOnLocalFiles();
printfnq("DONE.\n");
} else {
printfnq("Skipping intensive/long-running file iteration functions (enable with -f, should be done at least once!)\n");
}
initGroupProfileId(); initGroupProfileId();
initLocalGroup(); initLocalGroup();
@ -168,6 +183,11 @@ function fixupGroupURI()
function initConversation() function initConversation()
{ {
if (common_config('fix', 'upgrade_initConversation') <= 1) {
printfnq(sprintf("Skipping %s, fixed by previous upgrade.\n", __METHOD__));
return;
}
printfnq("Ensuring all conversations have a row in conversation table..."); printfnq("Ensuring all conversations have a row in conversation table...");
$notice = new Notice(); $notice = new Notice();
@ -197,6 +217,10 @@ function initConversation()
$conv->query($sql); $conv->query($sql);
} }
// This is something we should only have to do once unless introducing new, bad code.
if (DEBUG) printfnq(sprintf('Storing in config that we have done %s', __METHOD__));
common_config_set('fix', 'upgrade_initConversation', 1);
printfnq("DONE.\n"); printfnq("DONE.\n");
} }
@ -293,6 +317,11 @@ function initLocalGroup()
function initNoticeReshare() function initNoticeReshare()
{ {
if (common_config('fix', 'upgrade_initNoticeReshare') <= 1) {
printfnq(sprintf("Skipping %s, fixed by previous upgrade.\n", __METHOD__));
return;
}
printfnq("Ensuring all reshares have the correct verb and object-type..."); printfnq("Ensuring all reshares have the correct verb and object-type...");
$notice = new Notice(); $notice = new Notice();
@ -312,6 +341,10 @@ function initNoticeReshare()
} }
} }
// This is something we should only have to do once unless introducing new, bad code.
if (DEBUG) printfnq(sprintf('Storing in config that we have done %s', __METHOD__));
common_config_set('fix', 'upgrade_initNoticeReshare', 1);
printfnq("DONE.\n"); printfnq("DONE.\n");
} }
@ -424,20 +457,25 @@ function fixupFileGeometry()
if ($file->find()) { if ($file->find()) {
while ($file->fetch()) { while ($file->fetch()) {
if (DEBUG) printfnq(sprintf('Found file without width: %s\n', _ve($file->getFilename())));
// Set file geometrical properties if available // Set file geometrical properties if available
try { try {
$image = ImageFile::fromFileObject($file); $image = ImageFile::fromFileObject($file);
} catch (ServerException $e) { } catch (ServerException $e) {
// We couldn't make out an image from the file. // We couldn't make out an image from the file.
if (DEBUG) printfnq(sprintf('Could not make an image out of the file.\n'));
continue; continue;
} }
$orig = clone($file); $orig = clone($file);
$file->width = $image->width; $file->width = $image->width;
$file->height = $image->height; $file->height = $image->height;
if (DEBUG) printfnq(sprintf('Setting image file and with to %sx%s.\n', $file->width, $file->height));
$file->update($orig); $file->update($orig);
// FIXME: Do this more automagically inside ImageFile or so. // FIXME: Do this more automagically inside ImageFile or so.
if ($image->getPath() != $file->getPath()) { if ($image->getPath() != $file->getPath()) {
if (DEBUG) printfnq(sprintf('Deleting the temporarily stored ImageFile.\n'));
$image->unlink(); $image->unlink();
} }
unset($image); unset($image);