mirror of
https://github.com/nextcloud/server.git
synced 2026-10-16 03:51:45 +02:00
Set the location of migrated previews before inserting them, resolving it once per bucket and batch, instead of updating every preview after its insert. Orphaned previews are deleted from the object store by urn directly, with their filecache rows removed in bulk. Migrating 100 000 previews on an object store primary storage with PostgreSQL now takes 24s instead of 123s. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace OC\Preview\Storage;
|
|
|
|
use Exception;
|
|
use OC\Preview\Db\Preview;
|
|
use OCP\Files\NotFoundException;
|
|
use OCP\Files\NotPermittedException;
|
|
|
|
interface IPreviewStorage {
|
|
/**
|
|
* @param resource $stream
|
|
* @throws NotPermittedException
|
|
* @throws NotFoundException
|
|
*/
|
|
public function writePreview(Preview $preview, mixed $stream): int;
|
|
|
|
/**
|
|
* @param Preview $preview
|
|
* @return resource
|
|
* @throws NotPermittedException
|
|
* @throws NotFoundException
|
|
*/
|
|
public function readPreview(Preview $preview): mixed;
|
|
|
|
/**
|
|
* @throws NotPermittedException
|
|
*/
|
|
public function deletePreview(Preview $preview): void;
|
|
|
|
/**
|
|
* Delete the stored data of a preview that never got a database row, for
|
|
* example after losing the insert race on the unique constraint.
|
|
*
|
|
* Only backends that key their storage by the preview id hold data that
|
|
* belongs to this entity alone. The local storage derives its path from
|
|
* the preview specification, so the file is the very same one the winner
|
|
* of the race is now referencing and has to be kept.
|
|
*
|
|
* @throws NotPermittedException
|
|
*/
|
|
public function deleteUnreferencedPreview(Preview $preview): void;
|
|
|
|
/**
|
|
* Migration helper
|
|
*
|
|
* Called before the migrated preview rows are inserted, inside the same
|
|
* transaction. It may set storage specific fields on the previews but must
|
|
* not write the preview rows themselves.
|
|
*
|
|
* To remove at some point
|
|
* @param list<Preview> $previews
|
|
* @throws Exception
|
|
*/
|
|
public function migratePreviews(array $previews): void;
|
|
|
|
/**
|
|
* @throws NotPermittedException
|
|
* @throws NotFoundException
|
|
*/
|
|
public function scan(): int;
|
|
}
|