* performance boost for dealing with large structures

This commit is contained in:
Reinhard Pointner 2013-07-12 22:04:49 +00:00
parent 5d30c78dff
commit 99a6eb916e
1 changed files with 4 additions and 1 deletions

View File

@ -26,8 +26,11 @@ def clean(f) {
}
// memoize media folder status for performance
def hasMediaFiles = { dir -> dir.getFiles().find{ (it.isVideo() || it.isAudio()) && !isClutter(it) } }.memoize()
// delete clutter files in orphaned media folders
args.getFiles{ isClutter(it) && !it.dir.getFiles().find{ (it.isVideo() || it.isAudio()) && !isClutter(it) }}.each { clean(it) }
args.getFiles{ isClutter(it) && !hasMediaFiles(it.dir) }.each { clean(it) }
// delete empty folders but exclude given args
args.getFolders().sort().reverse().each { if (it.listFiles().length == 0) { if (deleteRootFolder || !args.contains(it)) clean(it) } }