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

未关闭 适合新手
#67,536 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php
领域
backend, databases

调研方向

阅读 lib/private/Preview/Storage/LocalPreviewStorage.php 中的 LocalPreviewStorage::fetchFilecacheByPathHashes(),并将其查询与 #58403 中为 deleteFolder() 添加的存储条件进行比较。确认如何获取 appdata 预览的根存储 ID,并检查迁移相关的测试。当查询将行限制在该存储范围内,且回归问题得到覆盖时,任务完成。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
PHP
星标
37.6k
派生
5.4k
平均合并
1 天 20 小时
30 天内合并 PR
605

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nextcloud/server 的其他 Issue

查看 nextcloud/server 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。