When using the 'Flush external images' function of this module, it calls file_unmanaged_delete_recursive() on the 'externals' directory, which attempts to delete everything in one request. On a large site with a highly populated directory (approx 20000 files), this times out for us on Pantheon with set limits. It looks like the D7 version of the module has a threshold to clean this directory up during cron runs, but we have a need to clear it manually after some other custom functionality happens in the site.
I am proposing that it use Drupal's Batch API to split the file deletion process into chunks so that the process does not time out. I will post a D8 patch to this issue, as well as a D7 version. Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | d7-use_batch_api-imagecache_external-3017032-9.patch | 5.13 KB | vinmassaro |
| #9 | Screenshot 2019-01-18 11.53.45.jpg | 16.84 KB | vinmassaro |
| #3 | d8-use_batch_api-imagecache_external-3017032-3.patch | 5.95 KB | vinmassaro |
Comments
Comment #2
vinmassaro commentedComment #3
vinmassaro commentedHere is a patch against 8.x-1.x.
Comment #4
BarisW commentedThanks for this great patch, really happy with it. I tested it and it works great. I found two small issues, which I will fix while committing the patch.
Double space
drupal_set_message is deprecated, should now be \Drupal::messenger()->addMessage
Comment #6
BarisW commentedThanks again!
Comment #7
vinmassaro commentedThanks! I think that double space may be required. I thought it was odd also. I originally needed this for D7 so I will put that backported patch here in a few days.
Comment #8
vinmassaro commentedComment #9
vinmassaro commentedHere is the D7 patch as promised. This includes the double space you mentioned removing in #4 - here is a screenshot of what the output looks like with only a single space, but I'm not sure why this happens, so maybe it should be added back to the D8 version:

The patch also adds the file count that I have posted a D8 patch for in #3026953: Add file count to 'flush external images' page. Thanks!
Comment #10
BarisW commentedComment #11
vinmassaro commented@BarisW: were you able to test my D7 patch? It is similar to the D8 version. Would love to get this committed. Thanks.