mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[fix] Don't waste time on dir/file attributes in subdirs (#5819)
An awful lot of effort was wasted getting attributes just for getting a count of the number of files/directories in subdirectories. Getting the count is pretty fast. Getting all the attributes is not, and in this context we don't even use the attributes. See <https://www.mobileread.com/forums/showthread.php?t=327085> and <https://gitter.im/koreader/koreader?at=5e3ac3b9e8a838355918ba13> for discussion.
This commit is contained in:
@@ -56,12 +56,16 @@ function FileChooser:init()
|
||||
end
|
||||
return true
|
||||
end
|
||||
self.list = function(path, dirs, files)
|
||||
self.list = function(path, dirs, files, count_only)
|
||||
-- lfs.dir directory without permission will give error
|
||||
local ok, iter, dir_obj = pcall(lfs.dir, path)
|
||||
if ok then
|
||||
for f in iter, dir_obj do
|
||||
if self.show_hidden or not string.match(f, "^%.[^.]") then
|
||||
if count_only then
|
||||
if self.show_hidden or not util.stringStartsWith(f, ".") then
|
||||
table.insert(dirs, true)
|
||||
end
|
||||
elseif self.show_hidden or not string.match(f, "^%.[^.]") then
|
||||
local filename = path.."/"..f
|
||||
local attributes = lfs.attributes(filename)
|
||||
if attributes ~= nil then
|
||||
@@ -211,7 +215,7 @@ function FileChooser:genItemTableFromPath(path)
|
||||
local sub_dirs = {}
|
||||
local dir_files = {}
|
||||
local subdir_path = self.path.."/"..dir.name
|
||||
self.list(subdir_path, sub_dirs, dir_files)
|
||||
self.list(subdir_path, sub_dirs, dir_files, true)
|
||||
local num_items = #sub_dirs + #dir_files
|
||||
local istr = ffiUtil.template(N_("1 item", "%1 items", num_items), num_items)
|
||||
local text
|
||||
|
||||
Reference in New Issue
Block a user