[minor] Rename file_cap to max_files (#14522)

See <https://github.com/koreader/koreader/pull/14521#issuecomment-3452885094>.
This commit is contained in:
David
2025-10-28 11:43:08 +00:00
committed by GitHub
parent b7d227a2cf
commit 5ac434183d
3 changed files with 8 additions and 8 deletions

View File

@@ -53,13 +53,13 @@ function filemanagerutil.splitFileNameType(filepath)
return filename_without_suffix, filetype
end
function filemanagerutil.getRandomFile(dir, match_func, file_cap)
function filemanagerutil.getRandomFile(dir, match_func, max_files)
local files = {}
util.findFiles(dir, function(file)
if match_func(file) then
table.insert(files, file)
end
end, false, file_cap)
end, false, max_files)
if #files > 0 then
math.randomseed(os.time())
return files[math.random(#files)]

View File

@@ -90,7 +90,7 @@ local function _getRandomImage(dir)
-- Slippery slope ahead! Ensure the number of files does not become unmanageable, otherwise we'll have performance issues.
-- Power users can increase this cap if needed. Beware though, this grows at O(n * c) where c increases with the number of files.
-- NOTE: empirically, a kindle 4 found and sorted 128 files in 0.274828 seconds.
local file_cap = G_reader_settings:readSetting("screensaver_file_cap") or 256
local max_files = G_reader_settings:readSetting("screensaver_max_files") or 256
-- If the user has set the option to cycle images alphabetically, we sort the files instead of picking a random one.
if G_reader_settings:isTrue("screensaver_cycle_images_alphabetically") then
local start_time = time.now()
@@ -99,7 +99,7 @@ local function _getRandomImage(dir)
if match_func(file) then
table.insert(files, file)
end
end, false, file_cap)
end, false, max_files)
if #files == 0 then return end
-- we have files, sort them in natural order, i.e z2 < z11 < z20
local sort = require("sort")
@@ -116,7 +116,7 @@ local function _getRandomImage(dir)
G_reader_settings:saveSetting("screensaver_cycle_index", index)
return files[index]
else -- Pick a random file (default behavior)
return filemanagerutil.getRandomFile(dir, match_func, file_cap)
return filemanagerutil.getRandomFile(dir, match_func, max_files)
end
end

View File

@@ -784,15 +784,15 @@ end
-- @string path
-- @func callback(fullpath, name, attr)
-- @bool recursive
-- @int file_cap (maximum number of files to find)
function util.findFiles(dir, cb, recursive, file_cap)
-- @int max_files (maximum number of files to find)
function util.findFiles(dir, cb, recursive, max_files)
recursive = recursive ~= false
local count = 0
local function scan(current)
local ok, iter, dir_obj = pcall(lfs.dir, current)
if not ok then return end
for f in iter, dir_obj do
if file_cap and count >= file_cap then return end
if max_files and count >= max_files then return end
local path = current.."/"..f
-- lfs can return nil here, as it will follow symlinks!
local attr = lfs.attributes(path) or {}