Stop scanning project file when a maximum limit is reached
To avoid excessive memory usage when opening in a directory with too many files. Introduce the config variable config.max_project_files to choose the limit. The mechanism introduced avoid using excessive memory but it fails to let user access all the files in the directory. A better implementation should not impose any limits but read each subdirectory on-demand, only as they are expanded in the tree-view.
This commit is contained in:
parent
7a856be6e4
commit
16e6a6db9d
|
@ -17,5 +17,6 @@ config.indent_size = 2
|
|||
config.tab_type = "soft"
|
||||
config.line_limit = 80
|
||||
config.max_symbols = 2000
|
||||
config.max_project_files = 2000
|
||||
|
||||
return config
|
||||
|
|
|
@ -34,6 +34,8 @@ local function project_scan_thread()
|
|||
local all = system.list_dir(path) or {}
|
||||
local dirs, files = {}, {}
|
||||
|
||||
local entries_count = 0
|
||||
local max_entries = config.max_project_files
|
||||
for _, file in ipairs(all) do
|
||||
if not common.match_pattern(file, config.ignore_files) then
|
||||
local file = (path ~= "." and path .. PATHSEP or "") .. file
|
||||
|
@ -41,6 +43,8 @@ local function project_scan_thread()
|
|||
if info and info.size < size_limit then
|
||||
info.filename = file
|
||||
table.insert(info.type == "dir" and dirs or files, info)
|
||||
entries_count = entries_count + 1
|
||||
if entries_count > max_entries then break end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -48,7 +52,10 @@ local function project_scan_thread()
|
|||
table.sort(dirs, compare_file)
|
||||
for _, f in ipairs(dirs) do
|
||||
table.insert(t, f)
|
||||
get_files(f.filename, t)
|
||||
if entries_count <= max_entries then
|
||||
local subdir_t, subdir_count = get_files(f.filename, t)
|
||||
entries_count = entries_count + subdir_count
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(files, compare_file)
|
||||
|
@ -56,14 +63,19 @@ local function project_scan_thread()
|
|||
table.insert(t, f)
|
||||
end
|
||||
|
||||
return t
|
||||
return t, entries_count
|
||||
end
|
||||
|
||||
while true do
|
||||
-- get project files and replace previous table if the new table is
|
||||
-- different
|
||||
local t = get_files(".")
|
||||
local t, entries_count = get_files(".")
|
||||
if diff_files(core.project_files, t) then
|
||||
if entries_count > config.max_project_files then
|
||||
core.status_view:show_message("!", style.accent,
|
||||
"Too many files in project directory: stopping reading at "..
|
||||
config.max_project_files.." files according to config.max_project_files.")
|
||||
end
|
||||
core.project_files = t
|
||||
core.redraw = true
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue