[wp-trac] [WordPress Trac] #54016: Media Library: Bulk delete elements in grid view takes very long
WordPress Trac
noreply at wordpress.org
Mon Jul 10 13:03:50 UTC 2023
#54016: Media Library: Bulk delete elements in grid view takes very long
-------------------------+------------------------------
Reporter: Presskopp | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version:
Severity: normal | Resolution:
Keywords: | Focuses: performance
-------------------------+------------------------------
Comment (by lukasbesch):
One problem in the bulk deletion process is that for every single media
item that is deleted, a request to admin-ajax is made. That can overload
the server pretty quickly.
**How about we bundle these request to single one with all the IDs?**
If we do that, the single request would probably take longer and could
timeout. To solve that problem, we could first mark all the items as "to
be deleted" (using the post_status) and run a scheduled job to clean up
everything in chunks again.
I am having this problem on a large site and found out that during the
deletion, also the postmeta table is scanned for the _thumbnail_id and the
corresponding entries are deleted. This is also slow on huge postmeta
tables.
So I imagine the process like that:
1. A request with all attachment IDs that should be deleted is sent.
2. These attachments get the post status `deleting`. They do not appear in
the media view anymore or at least cannot be selected. The filename is
still blocked for new uploads.
3. A scheduled job picks up these attachments and deletes them (one by one
or in chunks, oldest first?) and all relations like `_thumbnail_id`.
… maybe this should be opt-in or a plugin? Because not everyone has large
sites and a proper cronjob running, thus it would affect the (uncached)
frontend in terms of performance.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54016#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list