[wp-trac] [WordPress Trac] #50587: Provide short-circuit filter for scandir() in wp_unique_filename()
WordPress Trac
noreply at wordpress.org
Tue Jul 7 07:57:16 UTC 2020
#50587: Provide short-circuit filter for scandir() in wp_unique_filename()
-------------------------+-----------------------------
Reporter: joehoyle | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Upload | Version: 5.3
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
In https://core.trac.wordpress.org/ticket/42437, WordPress introduced an
enhancement to how unique filenames are calculated. The tl;dr of that
change was to run `scandir()` on the directory that a file will be placed
in, and iterate over all files, to check if there is any files that can
potentially conflict with the newly added file (or future resize
variants).
In situations where you have many thousands of files in your monthly
uploads directories, or where the upload DIR path is particularly slow for
access (such as remote file systems) this `scandir()` can cause a large
performance overhead.
I propose we add a "pre filter" to `scandir()` to allow plugins to
override the file fetching behaviour. The current implementation is quite
wasteful, as it will do a list on the whole directory, but then call
`preg_match()` on each file with `^$filename*...`. In situations where
plugins can get file listings by other mechanisms, a file list for
`$dir/$filename*` would return many fewer results but provide the same
file list needed for `_wp_check_existing_file_names()` for example.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50587>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list