Skip to content

Commit

Permalink
feat(core): add index to systemtag objecttype
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv committed Oct 18, 2024
1 parent 7aa556c commit fb52e4c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
42 changes: 42 additions & 0 deletions core/Migrations/Version31000Date20241018063111.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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;

/**
* Add objecttype index to systemtag_object_mapping
*/
class Version31000Date20241018063111 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();

if ($schema->hasTable('systemtag_object_mapping')) {
$table = $schema->getTable('systemtag_object_mapping');

if (!$table->hasIndex('systag_objecttype')) {
$table->addIndex(['objecttype'], 'systag_objecttype');
}
}

return $schema;
}
}
15 changes: 15 additions & 0 deletions lib/private/SystemTag/SystemTagObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,19 @@ function (ISystemTag $tag) {
);
}
}

public function getAvailableObjectTypes(): array {
$query = $this->connection->getQueryBuilder();
$query->selectDistinct('objecttype')
->from(self::RELATION_TABLE);

$result = $query->executeQuery();
$objectTypes = [];
while ($row = $result->fetch()) {
$objectTypes[] = $row['objecttype'];
}
$result->closeCursor();

return $objectTypes;
}
}
10 changes: 10 additions & 0 deletions lib/public/SystemTag/ISystemTagObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,14 @@ public function unassignTags(string $objId, string $objectType, $tagIds);
* @since 9.0.0
*/
public function haveTag($objIds, string $objectType, string $tagId, bool $all = true): bool;


/**
* Get the list of object types that have objects assigned to them.
*
* @return string[] list of object types
*
* @since 31.0.0
*/
public function getAvailableObjectTypes(): array;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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 = [31, 0, 0, 3];
$OC_Version = [31, 0, 0, 4];

// The human-readable string
$OC_VersionString = '31.0.0 dev';
Expand Down

0 comments on commit fb52e4c

Please sign in to comment.