Commit f30144b
fix(trashbin): avoid full filecache scan when restoring versions
`Trashbin::getVersionsFromTrash()` looked up a deleted file's versions with
`View::searchRaw('<name>.v%[.d<timestamp>]')`, which reaches
`Cache::search()` as `WHERE storage = ? AND name ILIKE ?`. The leading
literal + trailing `%` is non-sargable, and on MySQL the `ILIKE`->`COLLATE`
rewrite defeats any `name` index entirely, so every version restore — and
every `ExpireTrash`/`ExpireVersions` cron run that restores versions — full
scans `oc_filecache`. On large installations this is a heavy, repeated load
spike (issue #31682).
The version files for a given deleted file all live in a single known
directory under `files_trashbin/versions` (the folder the file was in, or
the versions root). Replace the whole-cache name search with an index-backed
`getDirectoryContent()` of that one directory (uses the existing
`(parent, name)` index) and filter the `<name>.v<version>[.d<timestamp>]`
entries in PHP. The directory to list is now passed in from both call sites
so version files of files deleted from inside a folder are still found.
Behavior is preserved: the same versions are returned, in the same shape.
Literal PHP matching is also slightly stricter than the previous SQL `LIKE`
(filenames containing `_`/`%` are no longer treated as wildcards).
Adds a regression test covering both the timestamped root lookup and the
non-timestamped sub-folder lookup, and asserting that version files of other
files / other timestamps are ignored.
Fixes #31682
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>1 parent 4921c51 commit f30144b
2 files changed
Lines changed: 96 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
680 | 680 | | |
681 | 681 | | |
682 | 682 | | |
683 | | - | |
| 683 | + | |
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
| |||
846 | 846 | | |
847 | 847 | | |
848 | 848 | | |
849 | | - | |
| 849 | + | |
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
| |||
957 | 957 | | |
958 | 958 | | |
959 | 959 | | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
960 | 965 | | |
961 | 966 | | |
962 | | - | |
| 967 | + | |
963 | 968 | | |
964 | 969 | | |
965 | 970 | | |
| |||
971 | 976 | | |
972 | 977 | | |
973 | 978 | | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
974 | 989 | | |
975 | | - | |
976 | | - | |
| 990 | + | |
| 991 | + | |
977 | 992 | | |
978 | 993 | | |
979 | | - | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
980 | 997 | | |
981 | 998 | | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
990 | 1008 | | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
991 | 1012 | | |
| 1013 | + | |
992 | 1014 | | |
993 | 1015 | | |
994 | 1016 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
910 | 910 | | |
911 | 911 | | |
912 | 912 | | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
913 | 973 | | |
914 | 974 | | |
915 | 975 | | |
| |||
0 commit comments