mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: limit memory usage for previewing large images (#2602)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
7cc250180f
commit
ca4fe2ced7
2 changed files with 11 additions and 5 deletions
|
|
@ -84,7 +84,7 @@ micro_workers = 10
|
|||
macro_workers = 10
|
||||
bizarre_retry = 3
|
||||
image_alloc = 536870912 # 512MB
|
||||
image_bound = [ 0, 0 ]
|
||||
image_bound = [ 5000, 5000 ]
|
||||
suppress_preload = false
|
||||
|
||||
[plugin]
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ function M:preload(job)
|
|||
return true
|
||||
end
|
||||
|
||||
local cmd = M.with_env()
|
||||
local cmd = M.with_limit()
|
||||
if job.args.flatten then
|
||||
cmd = cmd:arg("-flatten")
|
||||
end
|
||||
|
|
@ -46,10 +46,16 @@ end
|
|||
|
||||
function M:spot(job) require("file"):spot(job) end
|
||||
|
||||
function M.with_env()
|
||||
local cmd = Command("magick"):env("MAGICK_THREAD_LIMIT", 1)
|
||||
function M.with_limit()
|
||||
local cmd = Command("magick"):args { "-limit", "thread", 1 }
|
||||
if rt.tasks.image_alloc > 0 then
|
||||
cmd = cmd:env("MAGICK_MEMORY_LIMIT", rt.tasks.image_alloc)
|
||||
cmd = cmd:args({ "-limit", "memory", rt.tasks.image_alloc }):args { "-limit", "disk", "1MiB" }
|
||||
end
|
||||
if rt.tasks.image_bound[1] > 0 then
|
||||
cmd = cmd:args { "-limit", "width", rt.tasks.image_bound[1] }
|
||||
end
|
||||
if rt.tasks.image_bound[2] > 0 then
|
||||
cmd = cmd:args { "-limit", "height", rt.tasks.image_bound[2] }
|
||||
end
|
||||
return cmd
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue