]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Making upgrade.php somewhat more efficient by remember one-time-inits.
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 10 Jul 2017 17:39:26 +0000 (19:39 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 10 Jul 2017 18:27:37 +0000 (20:27 +0200)
scripts/upgrade.php

index f29c9f10bf702a7485b2eaa572313687579cbfc2..6752a3a1613e40fbed61ffc2df25e2a08e812634 100755 (executable)
@@ -20,8 +20,8 @@
 
 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
 
 
 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
 
-$shortoptions = 'x::';
-$longoptions = array('extensions=');
+$shortoptions = 'dfx::';
+$longoptions = array('debug', 'files', 'extensions=');
 
 $helptext = <<<END_OF_UPGRADE_HELP
 php upgrade.php [options]
 
 $helptext = <<<END_OF_UPGRADE_HELP
 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')) {
         fixupConversationURIs();
 
     if (Event::handle('StartUpgrade')) {
         fixupConversationURIs();
 
@@ -44,11 +53,17 @@ function main()
         fixupNoticeConversation();
         initConversation();
         fixupGroupURI();
         fixupNoticeConversation();
         initConversation();
         fixupGroupURI();
-        fixupFileGeometry();
-        deleteLocalFileThumbnailsWithoutFilename();
-        deleteMissingLocalFileThumbnails();
-        fixupFileThumbnailUrlhash();
-        setFilehashOnLocalFiles();
+        if ($iterate_files) {
+            printfnq("Running file iterations:\n");
+            printfnq("* "); fixupFileGeometry();
+            printfnq("* "); deleteLocalFileThumbnailsWithoutFilename();
+            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();
         initLocalGroup();
 
         initGroupProfileId();
         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...");
 
     $notice = new Notice();
     printfnq("Ensuring all conversations have a row in conversation table...");
 
     $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...");
     
     $notice = new Notice();
     printfnq("Ensuring all reshares have the correct verb and object-type...");
     
     $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()) {
         while ($file->fetch()) {
 
     if ($file->find()) {
         while ($file->fetch()) {
+            if (DEBUG) printfnq(sprintf('Found file without width: %s\n', _ve($file->getFilename())));
+
             // Set file geometrical properties if available
             try {
                 $image = ImageFile::fromFileObject($file);
             } catch (ServerException $e) {
                 // We couldn't make out an image from the file.
             // Set file geometrical properties if available
             try {
                 $image = ImageFile::fromFileObject($file);
             } catch (ServerException $e) {
                 // 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;
             }
             $orig = clone($file);
             $file->width = $image->width;
             $file->height = $image->height;
                 continue;
             }
             $orig = clone($file);
             $file->width = $image->width;
             $file->height = $image->height;
+            if (DEBUG) printfnq(sprintf('Setting image file and with to %sx%s.\n', $file->width, $file->height));
             $file->update($orig);
 
             // FIXME: Do this more automagically inside ImageFile or so.
             if ($image->getPath() != $file->getPath()) {
             $file->update($orig);
 
             // FIXME: Do this more automagically inside ImageFile or so.
             if ($image->getPath() != $file->getPath()) {
+                if (DEBUG) printfnq(sprintf('Deleting the temporarily stored ImageFile.\n'));
                 $image->unlink();
             }
             unset($image);
                 $image->unlink();
             }
             unset($image);