php - How to perform a statement inside a query to check existence of a file that has the query id as name with less resources in laravel -
i'm looking away see if query 'id' has folder same id name in file system, did slow down drive in future lots of files
$query = model::all(); if(input::get('field') == 'true'){ $filenames = scandir('img/folders'); $query->wherein('id', $filenames); }
as can see scan , names of folders inside 'folders' directory , create array it, app going have hundreds of thousands of folders in future , resolve before happens, further help
ps: other propositions differently welcome
do have reason believe scandir on directory large number of folders slow down?
you can query this:
if(input::has('field')){ $filenames = scandir('img/folders'); $query = model::wherein('id', $filenames)->get(); }
edit 1
you may find these links useful:
edit 2
there suggestions in links should able use guidance make own implementation. see it, based on links included first edit made, options use directoryiterator
, readdir
or chunking scandir
.
this basic way of doing guess readdir this:
$ids = model::lists('id'); $matches = []; if($handle = opendir('path/to/folders')) { while (($entry = readdir($handle)) !== false) { if(count($ids) === 0) { break; } if ($entry != "." && $entry != "..") { foreach ($ids $key => $value) { if($value === $entry) { $matches[] = $entry; unset($ids[$key]); } } } } closedir($handle); } return $matches;
Comments
Post a Comment