Legacy preview migration looks up filecache rows by path_hash without storage condition

Open Beginner friendly
#67,536 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend, databases

Research direction

Read LocalPreviewStorage::fetchFilecacheByPathHashes() in lib/private/Preview/Storage/LocalPreviewStorage.php and compare its query with the storage condition added for deleteFolder() in #58403. Confirm how the appdata previews’ root storage ID is available and inspect the migration’s related tests. Done when the lookup limits rows to that storage and the regression is covered.

Written by the indexing model from the issue text.

Description

bug feature: previews and thumbnails performance 🚀
Bug description

During the migration of legacy previews, LocalPreviewStorage::fetchFilecacheByPathHashes() selects rows with only a path_hash IN (…) condition across all shards:

https://github.com/nextcloud/server/blob/3a68340a6c806a18cdd0d9667a3b9ec5f096b135/lib/private/Preview/Storage/LocalPreviewStorage.php#L346-L357

There is no index on path_hash alone (only (storage, path_hash)), so every chunk of up to 1000 hashes is a full scan of oc_filecache. On large instances this makes the migration very slow and puts heavy load on the database. The same problem was fixed for deleteFolder() in #58403 by adding the storage condition.

Steps to reproduce

Found by code reading.

  1. Instance with a large oc_filecache and legacy previews in appdata_*/preview.
  2. Run the preview migration and watch the slow query log: SELECT … FROM oc_filecache WHERE path_hash IN (…) without storage.
Expected behavior

The query is restricted to the storage that holds the appdata previews (the root storage id), so the fs_storage_path_hash index is used.

Nextcloud version

master

Dominant language
PHP
Stars
37.6k
Forks
5.4k
Avg merge
1d 20h
Merged PRs (30d)
605

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nextcloud/server

All issues in nextcloud/server

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.