-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(core): Add index for jobs last_checked, reserved_at, time_sensitive #47324
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,45 @@ | ||||||||||
<?php | ||||||||||
|
||||||||||
declare(strict_types=1); | ||||||||||
|
||||||||||
/** | ||||||||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||||||||||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||||||||||
*/ | ||||||||||
|
||||||||||
namespace OC\Core\Migrations; | ||||||||||
|
||||||||||
use Closure; | ||||||||||
use OCP\DB\ISchemaWrapper; | ||||||||||
use OCP\Migration\IOutput; | ||||||||||
use OCP\Migration\SimpleMigrationStep; | ||||||||||
|
||||||||||
class Version31000Date20240819122840 extends SimpleMigrationStep { | ||||||||||
/** | ||||||||||
* @param IOutput $output | ||||||||||
* @param Closure(): ISchemaWrapper $schemaClosure | ||||||||||
* @param array $options | ||||||||||
* @return null|ISchemaWrapper | ||||||||||
*/ | ||||||||||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||||||||||
/** @var ISchemaWrapper $schema */ | ||||||||||
$schema = $schemaClosure(); | ||||||||||
|
||||||||||
$table = $schema->getTable('jobs'); | ||||||||||
|
||||||||||
# Remove previous indices | ||||||||||
if ($table->hasIndex('job_lastcheck_reserved')) { | ||||||||||
$table->dropIndex('job_lastcheck_reserved'); | ||||||||||
} | ||||||||||
if ($table->hasIndex('jobs_time_sensitive')) { | ||||||||||
$table->dropIndex('jobs_time_sensitive'); | ||||||||||
} | ||||||||||
|
||||||||||
# Add updated index | ||||||||||
if (!$table->hasIndex('job_last_reserved_sensitive')) { | ||||||||||
$table->addIndex(['last_checked', 'reserved_at', 'time_sensitive'], 'job_last_reserved_sensitive'); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding an index can be slow if there is a lot of data. Would it be possible to use https://docs.nextcloud.com/server/latest/developer_manual/basics/storage/migrations.html#replacing-indices instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, that's the first change she did in core/Application There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I didn't know about the possibility to replace indices. |
||||||||||
} | ||||||||||
Comment on lines
+38
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This should be done only on new installations and otherwise the change in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So just keep the old indices? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, deleting is fine. Just not creating new ones |
||||||||||
|
||||||||||
return $schema; | ||||||||||
} | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/nextcloud/server/pull/46974/files#diff-a13c08ddffcec08aa3dfe030b79869cd4b164cf35f9a4fff0e22dbe9848b552eR20 for examples, DB migrations for 30+ should be annotated for the new 30+ feature to work 👍