From d5038eeed52a459fa43b953c3b42a65a1b0d922c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Sun, 1 Jun 2025 09:20:17 +0800 Subject: [PATCH] perf: reduce file change event frequency (#2820) --- yazi-core/src/mgr/watcher.rs | 2 +- yazi-plugin/preset/plugins/noop.lua | 2 +- yazi-plugin/src/process/command.rs | 15 --------------- yazi-plugin/src/utils/call.rs | 24 ------------------------ yazi-plugin/src/utils/utils.rs | 3 --- 5 files changed, 2 insertions(+), 44 deletions(-) diff --git a/yazi-core/src/mgr/watcher.rs b/yazi-core/src/mgr/watcher.rs index 610e985f..ff6187fc 100644 --- a/yazi-core/src/mgr/watcher.rs +++ b/yazi-core/src/mgr/watcher.rs @@ -122,7 +122,7 @@ impl Watcher { async fn fan_out(rx: UnboundedReceiver) { // TODO: revert this once a new notification is implemented - let rx = UnboundedReceiverStream::new(rx).chunks_timeout(1000, Duration::from_millis(100)); + let rx = UnboundedReceiverStream::new(rx).chunks_timeout(1000, Duration::from_millis(350)); pin!(rx); while let Some(chunk) = rx.next().await { diff --git a/yazi-plugin/preset/plugins/noop.lua b/yazi-plugin/preset/plugins/noop.lua index 0ec794ee..f93a2e6b 100644 --- a/yazi-plugin/preset/plugins/noop.lua +++ b/yazi-plugin/preset/plugins/noop.lua @@ -1,6 +1,6 @@ local M = {} -function M:peek() end +function M:peek(job) ya.preview_widget(job, {}) end function M:seek() end diff --git a/yazi-plugin/src/process/command.rs b/yazi-plugin/src/process/command.rs index f9315fe1..07f2aaa4 100644 --- a/yazi-plugin/src/process/command.rs +++ b/yazi-plugin/src/process/command.rs @@ -152,21 +152,6 @@ impl UserData for Command { } Ok(ud) }); - // TODO: remove this - methods.add_function_mut("args", |lua, (ud, args): (AnyUserData, Vec)| { - crate::deprecate!( - lua, - "The `args()` method on `Command` is deprecated, use `arg()` instead in your {}\n\nSee #2752 for more details: https://github.com/sxyazi/yazi/pull/2752" - ); - - { - let mut me = ud.borrow_mut::()?; - for arg in args { - me.inner.arg(arg.to_string_lossy()); - } - } - Ok(ud) - }); methods.add_function_mut("cwd", |_, (ud, dir): (AnyUserData, mlua::String)| { ud.borrow_mut::()?.inner.current_dir(dir.to_str()?.as_ref()); Ok(ud) diff --git a/yazi-plugin/src/utils/call.rs b/yazi-plugin/src/utils/call.rs index 4712c95f..54058f98 100644 --- a/yazi-plugin/src/utils/call.rs +++ b/yazi-plugin/src/utils/call.rs @@ -21,34 +21,10 @@ impl Utils { }) } - // TODO: remove - pub(super) fn app_emit(lua: &Lua) -> mlua::Result { - lua.create_function(|lua, (name, args): (String, Table)| { - crate::deprecate!( - lua, - "`ya.app_emit()` is deprecated, use `ya.emit()` instead, in your {}\n\nSee #2653 for more details: https://github.com/sxyazi/yazi/pull/2653" - ); - emit!(Call(Cmd { name, args: Sendable::table_to_args(args)?, layer: Layer::App })); - Ok(()) - }) - } - pub(super) fn mgr_emit(lua: &Lua) -> mlua::Result { lua.create_function(|_, (name, args): (String, Table)| { emit!(Call(Cmd { name, args: Sendable::table_to_args(args)?, layer: Layer::Mgr })); Ok(()) }) } - - // TODO: remove - pub(super) fn input_emit(lua: &Lua) -> mlua::Result { - lua.create_function(|lua, (name, args): (String, Table)| { - crate::deprecate!( - lua, - "`ya.input_emit()` is deprecated, use `ya.emit()` instead, in your {}\n\nSee #2653 for more details: https://github.com/sxyazi/yazi/pull/2653" - ); - emit!(Call(Cmd { name, args: Sendable::table_to_args(args)?, layer: Layer::Input })); - Ok(()) - }) - } } diff --git a/yazi-plugin/src/utils/utils.rs b/yazi-plugin/src/utils/utils.rs index 44b139ea..e9b99bc1 100644 --- a/yazi-plugin/src/utils/utils.rs +++ b/yazi-plugin/src/utils/utils.rs @@ -17,10 +17,8 @@ pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result { // Call b"render" => Utils::render(lua)?, b"emit" => Utils::emit(lua)?, - b"app_emit" => Utils::app_emit(lua)?, b"mgr_emit" => Utils::mgr_emit(lua)?, b"manager_emit" => Utils::mgr_emit(lua)?, // TODO: remove this in the future - b"input_emit" => Utils::input_emit(lua)?, // Image b"image_info" => Utils::image_info(lua)?, @@ -44,7 +42,6 @@ pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result { // Preview b"preview_code" => Utils::preview_code(lua)?, b"preview_widget" => Utils::preview_widget(lua)?, - b"preview_widgets" => Utils::preview_widget(lua)?, // TODO: remove this in the future // Process b"proc_info" => Utils::proc_info(lua)?,