matjazp Posted March 20, 2017 Share Posted March 20, 2017 Any better way to find all images? The fastest way. Without script timeout. A lot of images... $timer = Debug::timer(); $allImages = array(); foreach (wire('fields')->find('type=FieldtypeImage') as $f) { foreach (wire('pages')->findMany("$f>0, include=all") as $p) { $images = $p->getUnformatted($f->name); foreach ($images as $i) { $allImages[] = $i; foreach ($i->getVariations() as $variation) $allImages[] = $variation; } } } $totalItems = count($allImages); echo "All images: " . $totalItems . " Timer: " . Debug::timer($timer); Link to comment Share on other sites More sharing options...
diogo Posted March 21, 2017 Share Posted March 21, 2017 Only thing I can think of is to limit the search also by template: foreach (wire('fields')->find("type=FieldtypeImage") as $f) { foreach (wire('templates') as $t) { foreach (wire('pages')->findMany("template=$t, $f>0, include=all") as $p) { // etc... } } } Link to comment Share on other sites More sharing options...
matjazp Posted March 21, 2017 Author Share Posted March 21, 2017 Thx, diogo. Found out that find/findmany is very fast, it's getVariations() call where 95% of time is lost, probably due to filesystem calls (DirectoryIterator). I guess there is no way to improve that? Link to comment Share on other sites More sharing options...
diogo Posted March 21, 2017 Share Posted March 21, 2017 You could also get the images directly from the assets/files directory with PHP. 1 Link to comment Share on other sites More sharing options...
matjazp Posted March 21, 2017 Author Share Posted March 21, 2017 8 minutes ago, diogo said: You could also get the images directly from the assets/files directory with PHP. I could, but that would give me all the files, not just images. And even I get the images by extension, I would have to know if image is of FiletypeFile of FieldtypeImage, and also would have to differentiate between originals and variations. If PW would store variations in DB... Also, I'm searching the forum and cant't find the post, where someone described (could be you?) how to iterate through a lot of pages (all of them) but without running out of memory and execution time. Link to comment Share on other sites More sharing options...
szabesz Posted March 21, 2017 Share Posted March 21, 2017 (edited) 50 minutes ago, matjazp said: where someone described (could be you?) how to iterate through a lot of pages (all of them) but without running out of memory and execution time. This one? Edited March 21, 2017 by szabesz link added :) 2 Link to comment Share on other sites More sharing options...
matjazp Posted March 21, 2017 Author Share Posted March 21, 2017 38 minutes ago, szabesz said: This one? This one! Thanks @szabesz 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now