Speedup dictionaries init (#3489)

When looking for .ifo to populate Dictionary settings menu,
avoid walking sub-directories once we found a .ifo, as these
sub-directories may contain a lot of images and other subdirs.
pull/3490/head
poire-z 7 years ago committed by Frans de Jonge
parent 2538189473
commit 338d14edb7

@ -27,25 +27,35 @@ local function getIfosInDir(path)
-- - No sorting, entries are processed in the order the dir_read_name() call -- - No sorting, entries are processed in the order the dir_read_name() call
-- returns them (inodes linked list) -- returns them (inodes linked list)
-- - If entry is a directory, Walk in it first and recurse -- - If entry is a directory, Walk in it first and recurse
-- With a small optimisation to avoid walking dict subdirectories that
-- may contain many images: if .ifo found, don't recurse subdirectories.
local ifos = {} local ifos = {}
local ok, iter, dir_obj = pcall(lfs.dir, path) local ok, iter, dir_obj = pcall(lfs.dir, path)
if ok then if ok then
local ifo_found = false
local subdirs = {}
for name in iter, dir_obj do for name in iter, dir_obj do
if name ~= "." and name ~= ".." then if name ~= "." and name ~= ".." then
local fullpath = path.."/"..name local fullpath = path.."/"..name
local attributes = lfs.attributes(fullpath) if fullpath:match("%.ifo$") then
if attributes ~= nil then table.insert(ifos, fullpath)
if attributes.mode == "directory" then ifo_found = true
local dirifos = getIfosInDir(fullpath) -- recurse elseif not ifo_found then -- don't check for dirs anymore if we found one .ifo
for _, ifo in pairs(dirifos) do local attributes = lfs.attributes(fullpath)
table.insert(ifos, ifo) if attributes ~= nil and attributes.mode == "directory" then
end table.insert(subdirs, fullpath)
elseif fullpath:match("%.ifo$") then
table.insert(ifos, fullpath)
end end
end end
end end
end end
if not ifo_found and #subdirs > 0 then
for _, subdir in pairs(subdirs) do
local dirifos = getIfosInDir(subdir)
for _, ifo in pairs(dirifos) do
table.insert(ifos, ifo)
end
end
end
end end
return ifos return ifos
end end

Loading…
Cancel
Save