Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix speedup of dictionaries init #3592

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions frontend/apps/reader/modules/readerdictionary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,28 @@ local function getIfosInDir(path)
-- - No sorting, entries are processed in the order the dir_read_name() call
-- returns them (inodes linked list)
-- - 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.
-- Don't walk into "res/" subdirectories, as per Stardict specs, they
-- may contain possibly many resource files (image, audio files...)
-- that could slow down our walk here.
local ifos = {}
local ok, iter, dir_obj = pcall(lfs.dir, path)
if ok then
local ifo_found = false
local subdirs = {}
for name in iter, dir_obj do
if name ~= "." and name ~= ".." then
if name ~= "." and name ~= ".." and name ~= "res" then
local fullpath = path.."/"..name
if fullpath:match("%.ifo$") then
table.insert(ifos, fullpath)
ifo_found = true
elseif not ifo_found then -- don't check for dirs anymore if we found one .ifo
local attributes = lfs.attributes(fullpath)
if attributes ~= nil and attributes.mode == "directory" then
table.insert(subdirs, fullpath)
local attributes = lfs.attributes(fullpath)
if attributes ~= nil then
if attributes.mode == "directory" then
local dirifos = getIfosInDir(fullpath) -- recurse
for _, ifo in pairs(dirifos) do
table.insert(ifos, ifo)
end
elseif fullpath:match("%.ifo$") then
table.insert(ifos, fullpath)
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
return ifos
end
Expand Down