我猜数据库读取将比这样的文件系统读取更快。
你最好运行一个 sql 查询并获得每个文件夹的计数,分组。
// Example Query
SELECT COUNT(file), folderId As Count FROM photos WHERE folderId IN ('1', '2') GROUP BY folder
// It would be beneficial to have a flag on the folders that would enable or disable them
// that way you're not iterating through folders that we already know are > 5k
// You would run this and have seperate query that would pull in these folder names
// and passing them to the above query.
SELECT foldername, folderId FROM folders WHERE countFlag = 0;
//Example Conditional.
if($Count > 5000):
// Over 5k Do Something
//Since were over 5k, set this folders flag to 1
// that way we arent iterating through it again
$countFlag = 1;
else:
// Under 5k Do Something else
endif;
注意:如果您需要实际的代码示例,我可以快速制作一些东西。上述示例省略了实际工作代码,仅用于理论目的。您将需要遍历返回的行,因为它们按文件夹分组。