| @@ -24,10 +24,9 @@ | ||
| 24 | 24 | `created_at` TIMESTAMP NULL, |
| 25 | 25 | `updated_at` TIMESTAMP NULL, |
| 26 | 26 | INDEX `idx_object_type` (`object_type`), |
| 27 | 27 | INDEX `idx_object_id` (`object_id`), |
| 28 | - INDEX `idx_key` (`key`), | |
| 29 | - INDEX `idx_object_type_created_at` (`object_type`, `created_at`) | |
| 28 | + INDEX `idx_key` (`key`) | |
| 30 | 29 | ) $charsetCollate;"; |
| 31 | 30 | $created = dbDelta($sql); |
| 32 | 31 | return $created; |
| 33 | 32 | } else { |
| @@ -60,23 +59,19 @@ | ||
| 60 | 59 | } |
| 61 | 60 | |
| 62 | 61 | // Desired indexes — keys and values are all hardcoded string literals. |
| 63 | 62 | $indexes = [ |
| 64 | - 'idx_object_type' => ['object_type'], | |
| 65 | - 'idx_object_id' => ['object_id'], | |
| 66 | - 'idx_key' => ['key'], | |
| 67 | - // Serves CleanupHandler::cleanExpiredAuthChallenges(), which purges | |
| 68 | - // rows by object_type + created_at on every hourly cron run. | |
| 69 | - 'idx_object_type_created_at' => ['object_type', 'created_at'], | |
| 63 | + 'idx_object_type' => 'object_type', | |
| 64 | + 'idx_object_id' => 'object_id', | |
| 65 | + 'idx_key' => 'key', | |
| 70 | 66 | ]; |
| 71 | 67 | |
| 72 | 68 | // Add missing indexes. $table is esc_sql()'d above; $index_name and |
| 73 | - // $columns are hardcoded array literals — no user input reaches this query. | |
| 74 | - foreach ($indexes as $index_name => $columns) { | |
| 69 | + // $column_name are hardcoded array literals — no user input reaches this query. | |
| 70 | + foreach ($indexes as $index_name => $column_name) { | |
| 75 | 71 | if (!in_array($index_name, $existing_index_names)) { |
| 76 | - $columnList = '`' . implode('`, `', $columns) . '`'; | |
| 77 | 72 | // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter,WordPress.DB.PreparedSQL.NotPrepared -- all identifiers are either esc_sql()'d or hardcoded literals. |
| 78 | - $wpdb->query("ALTER TABLE `{$table}` ADD INDEX `{$index_name}` ({$columnList})"); | |
| 73 | + $wpdb->query("ALTER TABLE `{$table}` ADD INDEX `{$index_name}` (`{$column_name}`)"); | |
| 79 | 74 | } |
| 80 | 75 | } |
| 81 | 76 | } |
| 82 | 77 | } |