ENH Improve performance of directory truncation#685
ENH Improve performance of directory truncation#685emteknetnz merged 1 commit intosilverstripe:3from
Conversation
| // Truncate any directories that held removed files | ||
| foreach (array_keys($tryTruncate) as $dir) { | ||
| $this->truncateDirectory($dir, $fs); | ||
| } |
There was a problem hiding this comment.
In almost 100% of cases all variants will be in the same directory, so we'll only have one call here, instead of one per variant.
The only reason we still have to get an array of possible directories is because the way findVariants() and FileIDHelper are implemented allows for the possibility of custom implementations where variants could be in different directories.
722a27f to
5e75c0b
Compare
de340c8 to
4b58d25
Compare
|
@axllent There's a bit more work for me to do on this PR but I think it's in a state where it can be validated. Can you please check if installing this PR makes a noticeable difference in your use case? |
|
Hi @GuySartorelli. To try give you the most accurate feedback, I set up a test project (with no custom modules) to ensure it's an accurate test. I programmatically created 5000 images, each with 7 variants (ie: total of 40,000 physical files in the directory). Then, in a build task I deleted the first 10 images and timed each deletion. Using the official Then I replaced the assets module with your repo ( WOW, talk about a performance boost, well done dude! 🥳 I can confirm the variants were correctly deleted too, and I even ran the task over all remaining images and can also confirm there were no stragglers afterwards. Mission success! FWIW, once complete, I think this should really be backported to SS5 too. Let me know if you require any more info. |
|
Awesome, thank you. That's the result I was hoping for 🚀
Some of this will be merged into 5.4, but some of it requires new API so will need to be in 6.1. |
|
Awesome.
That's a shame given we can't plan around an unspecified date (and this heavily impacts a project we're working on), but I understand re: the API change. Oh well, the main thing is you have hit the nail on the head so it will be fixed at some point! |
CMS 6.1 will be released in October (minor releases are every 6 months in April and October as per the minor release policy). |
0127032 to
756c6ba
Compare
| ) { | ||
| $this->pathPrefixer = new PathPrefixer($location); | ||
| $this->linkHandling = $linkHandling; | ||
| $this->visibility = $visibility ??= new PortableVisibilityConverter(); |
There was a problem hiding this comment.
See parent class constructor - though since that sets private properties we have to do it here as well to access them
756c6ba to
997ae16
Compare
emteknetnz
left a comment
There was a problem hiding this comment.
Just a quick question before I review further:
We now have this in SilverStripe\Assets\Flysystem\FileSystem
/**
* Check if a directory is empty
*/
public function isEmpty(string $location): bool
{
// listContents() uses generators, so we can start the iterator and return false if there's a single item.
// In most cases this will be orders of magnitude faster than checking if $this->listContents($location)->toArray() is empty.
foreach ($this->listContents($location) as $item) {
return false;
}
return true;
}Is this all we need? Do we actually need all of the glob stuff to solve the original issue?
We need both, as they both improve things in different ways, for slightly different use cases.
|
997ae16 to
1b5fc89
Compare
1b5fc89 to
d131ffb
Compare
d131ffb to
dda86b2
Compare
- Better performance to check if directory is empty - Better performance checking for variants using glob where possible
dda86b2 to
8c66e83
Compare
This PR does a few things:
FlysystemAssetStore::truncateDirectory(), check if the directory is empty more efficiently (see ENH Improve performance of directory truncation #685 (comment) and newFilesystem::isEmpty()method)Callnow done in FIX Don't try truncate the same directory multiple times. #686FlysystemAssetStore::truncateDirectory()less often (mostly useful for adapters that can't do the empty check efficiently, e.g. S3 adapter which gets 1000 files per paginated fetch)GlobContentListerif they want performance gains. This would be possible with the FTP adapter for example but not with the AWS S3 adapter.TODO
Dependencies
Requires the following PRs to be merged first (they are currently included in this PR's changset but will be removed on rebase after those are merged into the base branch)
Issue