]> source.dussan.org Git - nextcloud-server.git/commitdiff
better indexes
authorMaxence Lange <maxence@artificial-owl.com>
Wed, 24 Jan 2024 21:00:18 +0000 (20:00 -0100)
committerMaxence Lange <maxence@artificial-owl.com>
Wed, 24 Jan 2024 21:01:56 +0000 (20:01 -0100)
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
core/Migrations/Version28000Date20231126110901.php [new file with mode: 0644]
core/Migrations/Version29000Date20231126110901.php
core/Migrations/Version29000Date20240124132201.php [new file with mode: 0644]
core/Migrations/Version29000Date20240124132202.php [new file with mode: 0644]
lib/composer/composer/autoload_classmap.php
lib/composer/composer/autoload_static.php
lib/private/AppConfig.php
version.php

diff --git a/core/Migrations/Version28000Date20231126110901.php b/core/Migrations/Version28000Date20231126110901.php
new file mode 100644 (file)
index 0000000..ec1e80d
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright 2023 Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Core\Migrations;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+/**
+ * Create new fields for type and lazy loading in appconfig for the new IAppConfig API.
+ */
+class Version28000Date20231126110901 extends SimpleMigrationStep {
+       public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
+               return null;
+
+               /**
+                * this migration was needed during Nextcloud 28 to prep the migration to 29 and a
+                * new IAppConfig as its API require 'lazy' and 'type' database field.
+                *
+                * some changes in the migration process and the expected result have made its execution
+                * useless, therefore ignored.
+                *
+                * @see Version29000Date20240124132201
+                * @see Version29000Date20240124132202
+                */
+               //              /** @var ISchemaWrapper $schema */
+               //              $schema = $schemaClosure();
+               //
+               //              if (!$schema->hasTable('appconfig')) {
+               //                      return null;
+               //              }
+               //
+               //              $table = $schema->getTable('appconfig');
+               //              if ($table->hasColumn('lazy')) {
+               //                      return null;
+               //              }
+               //
+               //              // type=2 means value is typed as MIXED
+               //              $table->addColumn('type', Types::INTEGER, ['notnull' => true, 'default' => 2]);
+               //              $table->addColumn('lazy', Types::BOOLEAN, ['notnull' => false, 'default' => false]);
+               //
+               //              return $schema;
+       }
+}
index 3867074e013c859bb6977050413a0e7906bd3894..cbbac6b77776dc357600ea5a5a3a5e48d090e0a9 100644 (file)
@@ -39,27 +39,34 @@ class Version29000Date20231126110901 extends SimpleMigrationStep {
                /** @var ISchemaWrapper $schema */
                $schema = $schemaClosure();
 
-               if (!$schema->hasTable('appconfig')) {
-                       return null;
-               }
-
                $table = $schema->getTable('appconfig');
                if ($table->hasColumn('lazy')) {
                        return null;
                }
 
-               // type=2 means value is typed as MIXED
-               $table->addColumn('type', Types::INTEGER, ['notnull' => true, 'default' => 2]);
-               $table->addColumn('lazy', Types::BOOLEAN, ['notnull' => false, 'default' => false]);
-
-               if ($table->hasIndex('appconfig_config_key_index')) {
-                       $table->dropIndex('appconfig_config_key_index');
-               }
-
-               $table->addIndex(['lazy'], 'ac_lazy_i');
-               $table->addIndex(['appid', 'lazy'], 'ac_app_lazy_i');
-               $table->addIndex(['appid', 'lazy', 'configkey'], 'ac_app_lazy_key_i');
+               /**
+                * This code is now useless, after a discussion about boolean on oracle;
+                * it has been decided to use another type for the lazy field
+                *
+                * a better migration process is available there:
+                *
+                * @see Version29000Date20240124132201 for the revert of current migration
+                * @see Version29000Date20240124132202 for the new migration process
+                */
+               return null;
 
-               return $schema;
+               //              // type=2 means value is typed as MIXED
+               //              $table->addColumn('type', Types::INTEGER, ['notnull' => true, 'default' => 2]);
+               //              $table->addColumn('lazy', Types::BOOLEAN, ['notnull' => false, 'default' => false]);
+               //
+               //              if ($table->hasIndex('appconfig_config_key_index')) {
+               //                      $table->dropIndex('appconfig_config_key_index');
+               //              }
+               //
+               //              $table->addIndex(['lazy'], 'ac_lazy_i');
+               //              $table->addIndex(['appid', 'lazy'], 'ac_app_lazy_i');
+               //              $table->addIndex(['appid', 'lazy', 'configkey'], 'ac_app_lazy_key_i');
+               //
+               //              return $schema;
        }
 }
diff --git a/core/Migrations/Version29000Date20240124132201.php b/core/Migrations/Version29000Date20240124132201.php
new file mode 100644 (file)
index 0000000..86c2197
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright 2023 Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Core\Migrations;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\DB\Types;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+/**
+ * Create new fields for type and lazy loading in appconfig for the new IAppConfig API.
+ */
+class Version29000Date20240124132201 extends SimpleMigrationStep {
+       public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
+               /** @var ISchemaWrapper $schema */
+               $schema = $schemaClosure();
+
+               $table = $schema->getTable('appconfig');
+
+               // we will drop 'lazy', we start to clean related indexes first
+               if ($table->hasIndex('ac_lazy_i')) {
+                       $table->dropIndex('ac_lazy_i');
+               }
+
+               if ($table->hasIndex('ac_app_lazy_i')) {
+                       $table->dropIndex('ac_app_lazy_i');
+               }
+
+               if ($table->hasIndex('ac_app_lazy_key_i')) {
+                       $table->dropIndex('ac_app_lazy_key_i');
+               }
+
+               if ($table->hasColumn('lazy')) {
+                       $table->dropColumn('lazy');
+               }
+
+               // create field 'type' if it does not exist yet, or fix the fact that it is missing 'unsigned'
+               if (!$table->hasColumn('type')) {
+                       $table->addColumn('type', Types::INTEGER, ['notnull' => true, 'default' => 2, 'unsigned' => true]);
+               } else {
+                       $table->modifyColumn('type', ['notnull' => true, 'default' => 2, 'unsigned' => true]);
+               }
+
+               // not needed anymore
+               if ($table->hasIndex('appconfig_config_key_index')) {
+                       $table->dropIndex('appconfig_config_key_index');
+               }
+
+               return $schema;
+       }
+}
diff --git a/core/Migrations/Version29000Date20240124132202.php b/core/Migrations/Version29000Date20240124132202.php
new file mode 100644 (file)
index 0000000..b393477
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright 2023 Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Core\Migrations;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\DB\Types;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+/**
+ * Create new fields for type and lazy loading in appconfig for the new IAppConfig API.
+ */
+class Version29000Date20240124132202 extends SimpleMigrationStep {
+       public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
+               /** @var ISchemaWrapper $schema */
+               $schema = $schemaClosure();
+
+               $table = $schema->getTable('appconfig');
+               $table->addColumn('lazy', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'length' => 1, 'unsigned' => true]);
+
+               /**
+                * we only need an index on lazy, the group 'appid'+'configkey' already
+                * exists as primary ({@see Version13000Date20170718121200})
+                */
+               $table->addIndex(['lazy'], 'ac_lazy_i');
+
+               return $schema;
+       }
+}
index f1de00a49bf89cb624d84184e350ccc06bd3160f..2fffd0c2f2db3cd9886eaa6ea327c5befc2d04ef 100644 (file)
@@ -1241,8 +1241,11 @@ return array(
     'OC\\Core\\Migrations\\Version28000Date20230906104802' => $baseDir . '/core/Migrations/Version28000Date20230906104802.php',
     'OC\\Core\\Migrations\\Version28000Date20231004103301' => $baseDir . '/core/Migrations/Version28000Date20231004103301.php',
     'OC\\Core\\Migrations\\Version28000Date20231103104802' => $baseDir . '/core/Migrations/Version28000Date20231103104802.php',
+    'OC\\Core\\Migrations\\Version28000Date20231126110901' => $baseDir . '/core/Migrations/Version28000Date20231126110901.php',
     'OC\\Core\\Migrations\\Version29000Date20231126110901' => $baseDir . '/core/Migrations/Version29000Date20231126110901.php',
     'OC\\Core\\Migrations\\Version29000Date20231213104850' => $baseDir . '/core/Migrations/Version29000Date20231213104850.php',
+    'OC\\Core\\Migrations\\Version29000Date20240124132201' => $baseDir . '/core/Migrations/Version29000Date20240124132201.php',
+    'OC\\Core\\Migrations\\Version29000Date20240124132202' => $baseDir . '/core/Migrations/Version29000Date20240124132202.php',
     'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
     'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
     'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',
index 017918b3f44b8ef66b91feb228ff41408b0e6d32..d38db8050cc689735386dda03822971fdb304618 100644 (file)
@@ -1274,8 +1274,11 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
         'OC\\Core\\Migrations\\Version28000Date20230906104802' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20230906104802.php',
         'OC\\Core\\Migrations\\Version28000Date20231004103301' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20231004103301.php',
         'OC\\Core\\Migrations\\Version28000Date20231103104802' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20231103104802.php',
+        'OC\\Core\\Migrations\\Version28000Date20231126110901' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20231126110901.php',
         'OC\\Core\\Migrations\\Version29000Date20231126110901' => __DIR__ . '/../../..' . '/core/Migrations/Version29000Date20231126110901.php',
         'OC\\Core\\Migrations\\Version29000Date20231213104850' => __DIR__ . '/../../..' . '/core/Migrations/Version29000Date20231213104850.php',
+        'OC\\Core\\Migrations\\Version29000Date20240124132201' => __DIR__ . '/../../..' . '/core/Migrations/Version29000Date20240124132201.php',
+        'OC\\Core\\Migrations\\Version29000Date20240124132202' => __DIR__ . '/../../..' . '/core/Migrations/Version29000Date20240124132202.php',
         'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
         'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',
         'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php',
index d15aff37c5ba169086fc08652ad835140e093fd9..8064fe186f83c32f2d031f0391c7711f6cb1158f 100644 (file)
@@ -83,6 +83,9 @@ class AppConfig implements IAppConfig {
        /**
         * $migrationCompleted is only needed to manage the previous structure
         * of the database during the upgrading process to nc29.
+        *
+        * only when upgrading from a version prior 28.0.2
+        *
         * @TODO: remove this value in Nextcloud 30+
         */
        private bool $migrationCompleted = true;
@@ -735,7 +738,7 @@ class AppConfig implements IAppConfig {
                $insert = $this->connection->getQueryBuilder();
                $insert->insert('appconfig')
                           ->setValue('appid', $insert->createNamedParameter($app))
-                          ->setValue('lazy', $insert->createNamedParameter($lazy, IQueryBuilder::PARAM_BOOL))
+                          ->setValue('lazy', $insert->createNamedParameter(($lazy) ? 1 : 0, IQueryBuilder::PARAM_INT))
                           ->setValue('type', $insert->createNamedParameter($type, IQueryBuilder::PARAM_INT))
                           ->setValue('configkey', $insert->createNamedParameter($key))
                           ->setValue('configvalue', $insert->createNamedParameter($value));
@@ -788,7 +791,7 @@ class AppConfig implements IAppConfig {
                        $update = $this->connection->getQueryBuilder();
                        $update->update('appconfig')
                                   ->set('configvalue', $update->createNamedParameter($value))
-                                  ->set('lazy', $update->createNamedParameter($lazy, IQueryBuilder::PARAM_BOOL))
+                                  ->set('lazy', $update->createNamedParameter(($lazy) ? 1 : 0, IQueryBuilder::PARAM_INT))
                                   ->set('type', $update->createNamedParameter($type, IQueryBuilder::PARAM_INT))
                                   ->where($update->expr()->eq('appid', $update->createNamedParameter($app)))
                                   ->andWhere($update->expr()->eq('configkey', $update->createNamedParameter($key)));
@@ -925,7 +928,7 @@ class AppConfig implements IAppConfig {
 
                $update = $this->connection->getQueryBuilder();
                $update->update('appconfig')
-                          ->set('lazy', $update->createNamedParameter($lazy, IQueryBuilder::PARAM_BOOL))
+                          ->set('lazy', $update->createNamedParameter($lazy ? 1 : 0, IQueryBuilder::PARAM_INT))
                           ->where($update->expr()->eq('appid', $update->createNamedParameter($app)))
                           ->andWhere($update->expr()->eq('configkey', $update->createNamedParameter($key)));
                $update->executeStatement();
@@ -1157,21 +1160,13 @@ class AppConfig implements IAppConfig {
                if (!$this->migrationCompleted) {
                        $qb->select('appid', 'configkey', 'configvalue');
                } else {
-                       $qb->select('appid', 'configkey', 'configvalue', 'type', 'lazy');
+                       // we only need value from lazy when loadConfig does not specify it
+                       $qb->select('appid', 'configkey', 'configvalue', 'type');
+
                        if ($lazy !== null) {
-                               if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
-                                       // Oracle does not like empty string nor false boolean !?
-                                       if ($lazy) {
-                                               $qb->where($qb->expr()->eq('lazy', $qb->createNamedParameter('1', IQueryBuilder::PARAM_INT)));
-                                       } else {
-                                               $qb->where($qb->expr()->orX(
-                                                       $qb->expr()->isNull('lazy'),
-                                                       $qb->expr()->eq('lazy', $qb->createNamedParameter('0', IQueryBuilder::PARAM_INT))
-                                               ));
-                                       }
-                               } else {
-                                       $qb->where($qb->expr()->eq('lazy', $qb->createNamedParameter($lazy, IQueryBuilder::PARAM_BOOL)));
-                               }
+                               $qb->where($qb->expr()->eq('lazy', $qb->createNamedParameter($lazy ? 1 : 0, IQueryBuilder::PARAM_INT)));
+                       } else {
+                               $qb->addSelect('lazy');
                        }
                }
 
@@ -1195,9 +1190,8 @@ class AppConfig implements IAppConfig {
 
                $rows = $result->fetchAll();
                foreach ($rows as $row) {
-                       // if migration is not completed, 'lazy' and 'type' does not exist in $row
-                       // also on oracle, lazy can be null ...
-                       if ($row['lazy'] ?? false) {
+                       // most of the time, 'lazy' is not in the select because its value is already known
+                       if (($row['lazy'] ?? ($lazy ?? 0) ? 1 : 0) === 1) {
                                $cache = &$this->lazyCache;
                        } else {
                                $cache = &$this->fastCache;
@@ -1282,6 +1276,15 @@ class AppConfig implements IAppConfig {
         * @deprecated
         */
        public function setValue($app, $key, $value) {
+               /**
+                * TODO: would it be overkill, or decently improve performance, to catch
+                * call to this method with $key='enabled' and 'hide' config value related
+                * to $app when the app is disabled (by modifying entry in database: lazy=lazy+2)
+                * or enabled (lazy=lazy-2)
+                *
+                * this solution would remove the loading of config values from disabled app
+                * unless calling the method {@see loadConfigAll()}
+                */
                return $this->setTypedValue($app, $key, (string)$value, false, self::VALUE_MIXED);
        }
 
index 47ada5b87774c3913cf0650322d63c3cf23355c5..a1855bfad5aa2387cd8ee8d0717cc627fcfbbcc0 100644 (file)
@@ -30,7 +30,7 @@
 // between betas, final and RCs. This is _not_ the public version number. Reset minor/patch level
 // when updating major/minor version number.
 
-$OC_Version = [29, 0, 0, 4];
+$OC_Version = [29, 0, 0, 5];
 
 // The human-readable string
 $OC_VersionString = '29.0.0 dev';