Browse Source

perf: delete commonly used custom properties instead of setting the default value

Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
pull/54405/head
Richard Steinmetz 2 months ago
parent
commit
7c0ffc0759
No known key found for this signature in database GPG Key ID: 27137D9E7D273FB2
  1. 2
      apps/dav/appinfo/info.xml
  2. 1
      apps/dav/composer/composer/autoload_classmap.php
  3. 1
      apps/dav/composer/composer/autoload_static.php
  4. 19
      apps/dav/lib/DAV/CustomPropertiesBackend.php
  5. 53
      apps/dav/lib/Migration/Version1034Date20250813093701.php

2
apps/dav/appinfo/info.xml

@ -10,7 +10,7 @@
<name>WebDAV</name>
<summary>WebDAV endpoint</summary>
<description>WebDAV endpoint</description>
<version>1.34.0</version>
<version>1.34.1</version>
<licence>agpl</licence>
<author>owncloud.org</author>
<namespace>DAV</namespace>

1
apps/dav/composer/composer/autoload_classmap.php

@ -353,6 +353,7 @@ return array(
'OCA\\DAV\\Migration\\Version1029Date20231004091403' => $baseDir . '/../lib/Migration/Version1029Date20231004091403.php',
'OCA\\DAV\\Migration\\Version1030Date20240205103243' => $baseDir . '/../lib/Migration/Version1030Date20240205103243.php',
'OCA\\DAV\\Migration\\Version1031Date20240610134258' => $baseDir . '/../lib/Migration/Version1031Date20240610134258.php',
'OCA\\DAV\\Migration\\Version1034Date20250813093701' => $baseDir . '/../lib/Migration/Version1034Date20250813093701.php',
'OCA\\DAV\\Model\\ExampleEvent' => $baseDir . '/../lib/Model/ExampleEvent.php',
'OCA\\DAV\\Paginate\\LimitedCopyIterator' => $baseDir . '/../lib/Paginate/LimitedCopyIterator.php',
'OCA\\DAV\\Paginate\\PaginateCache' => $baseDir . '/../lib/Paginate/PaginateCache.php',

1
apps/dav/composer/composer/autoload_static.php

@ -368,6 +368,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Migration\\Version1029Date20231004091403' => __DIR__ . '/..' . '/../lib/Migration/Version1029Date20231004091403.php',
'OCA\\DAV\\Migration\\Version1030Date20240205103243' => __DIR__ . '/..' . '/../lib/Migration/Version1030Date20240205103243.php',
'OCA\\DAV\\Migration\\Version1031Date20240610134258' => __DIR__ . '/..' . '/../lib/Migration/Version1031Date20240610134258.php',
'OCA\\DAV\\Migration\\Version1034Date20250813093701' => __DIR__ . '/..' . '/../lib/Migration/Version1034Date20250813093701.php',
'OCA\\DAV\\Model\\ExampleEvent' => __DIR__ . '/..' . '/../lib/Model/ExampleEvent.php',
'OCA\\DAV\\Paginate\\LimitedCopyIterator' => __DIR__ . '/..' . '/../lib/Paginate/LimitedCopyIterator.php',
'OCA\\DAV\\Paginate\\PaginateCache' => __DIR__ . '/..' . '/../lib/Paginate/PaginateCache.php',

19
apps/dav/lib/DAV/CustomPropertiesBackend.php

@ -118,6 +118,13 @@ class CustomPropertiesBackend implements BackendInterface {
'{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL' => Href::class,
];
/**
* Map of well-known property names to default values
*/
private const PROPERTY_DEFAULT_VALUES = [
'{http://owncloud.org/ns}calendar-enabled' => '1',
];
/**
* Properties cache
*
@ -422,6 +429,14 @@ class CustomPropertiesBackend implements BackendInterface {
return $props;
}
private function isPropertyDefaultValue(string $name, mixed $value): bool {
if (!isset(self::PROPERTY_DEFAULT_VALUES[$name])) {
return false;
}
return self::PROPERTY_DEFAULT_VALUES[$name] === $value;
}
/**
* @throws Exception
*/
@ -438,8 +453,8 @@ class CustomPropertiesBackend implements BackendInterface {
'propertyName' => $propertyName,
];
// If it was null, we need to delete the property
if (is_null($propertyValue)) {
// If it was null or set to the default value, we need to delete the property
if (is_null($propertyValue) || $this->isPropertyDefaultValue($propertyName, $propertyValue)) {
if (array_key_exists($propertyName, $existing)) {
$deleteQuery = $deleteQuery ?? $this->createDeleteQuery();
$deleteQuery

53
apps/dav/lib/Migration/Version1034Date20250813093701.php

@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;
class Version1034Date20250813093701 extends SimpleMigrationStep {
public function __construct(
private IDBConnection $db,
) {
}
/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
#[Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$qb = $this->db->getQueryBuilder();
$qb->delete('properties')
->where($qb->expr()->eq(
'propertyname',
$qb->createNamedParameter(
'{http://owncloud.org/ns}calendar-enabled',
IQueryBuilder::PARAM_STR,
),
IQueryBuilder::PARAM_STR,
))
->andWhere($qb->expr()->eq(
'propertyvalue',
$qb->createNamedParameter(
'1',
IQueryBuilder::PARAM_STR,
),
IQueryBuilder::PARAM_STR,
))
->executeStatement();
}
}
Loading…
Cancel
Save