Repository: sxyazi/yazi
File: yazi-core/src/mgr/watcher.rs (Rust)

Code before:
		let out_tx_ = out_tx.clone();
		let handler = move |res: Result<notify::Event, notify::Error>| {
			let Ok(event) = res else { return };
			if event.kind.is_access() {
				return;
			}
			Self::push_files_impl(&out_tx_, event.paths.into_iter().map(Url::from));
		};

		let config = notify::Config::default().with_poll_interval(Duration::from_millis(500));
		if yazi_adapter::WSL.get() || cfg!(target_os = "netbsd") {
			tokio::spawn(Self::fan_in(in_rx, PollWatcher::new(handler, config).unwrap()));
		} else {
			tokio::spawn(Self::fan_in(in_rx, RecommendedWatcher::new(handler, config).unwrap()));
		}

		#[cfg(any(target_os = "linux", target_os = "macos"))]
		yazi_fs::mounts::Partitions::monitor(yazi_fs::mounts::PARTITIONS.clone(), || {
			yazi_macro::err!(yazi_dds::Pubsub::pub_from_mount())
		});

		tokio::spawn(Self::fan_out(out_rx));
		Self { in_tx, out_tx }
	}

	pub(super) fn watch(&mut self, mut new: HashSet<&Url>) {
		new.retain(|&u| u.is_regular());
		self.in_tx.send(new.into_iter().cloned().collect()).ok();
	}

	pub(super) fn push_files(&self, urls: Vec<Url>) {
		Self::push_files_impl(&self.out_tx, urls.into_iter());
	}

	fn push_files_impl(out_tx: &mpsc::UnboundedSender<Url>, urls: impl Iterator<Item = Url>) {
		let (mut parents, watched) = (HashSet::new(), WATCHED.read());
		for u in urls {
			let Some(p) = u.parent_url() else { continue };
			if !watched.contains(&p) && !LINKED.read().from_dir(&p).any(|u| watched.contains(u)) {
				continue;
			}
			out_tx.send(u).ok();
			if !parents.contains(&p) {
				out_tx.send(p.clone()).ok();
				parents.insert(p);
			}
		}
	}

	// TODO: performance improvement
	pub(super) fn trigger_dirs(&self, folders: &[&Folder]) {

Review comment (refactor):
The new implementation collects URLs into a Vec without deduplication, while the previous HashSet-based approach guaranteed uniqueness. Consider deduplicating (e.g., collect into a HashSet or use an iterator adapter) to avoid registering duplicate watch targets.

Code after:
		let out_tx_ = out_tx.clone();
		let handler = move |res: Result<notify::Event, notify::Error>| {
			let Ok(event) = res else { return };
			if event.kind.is_access() {
				return;
			}
			Self::push_files_impl(&out_tx_, event.paths.into_iter().map(Url::from));
		};

		let config = notify::Config::default().with_poll_interval(Duration::from_millis(500));
		if yazi_adapter::WSL.get() || cfg!(target_os = "netbsd") {
			tokio::spawn(Self::fan_in(in_rx, PollWatcher::new(handler, config).unwrap()));
		} else {
			tokio::spawn(Self::fan_in(in_rx, RecommendedWatcher::new(handler, config).unwrap()));
		}

		#[cfg(any(target_os = "linux", target_os = "macos"))]
		yazi_fs::mounts::Partitions::monitor(yazi_fs::mounts::PARTITIONS.clone(), || {
			yazi_macro::err!(yazi_dds::Pubsub::pub_from_mount())
		});

		tokio::spawn(Self::fan_out(out_rx));
		Self { in_tx, out_tx }
	}

	pub(super) fn watch<'a>(&mut self, it: impl Iterator<Item = &'a Url>) {
		self.in_tx.send(it.filter(|u| u.is_regular()).cloned().collect()).ok();
	}

	pub(super) fn push_files(&self, urls: Vec<Url>) {
		Self::push_files_impl(&self.out_tx, urls.into_iter());
	}

	fn push_files_impl(out_tx: &mpsc::UnboundedSender<Url>, urls: impl Iterator<Item = Url>) {
		let (mut parents, watched) = (HashSet::new(), WATCHED.read());
		for u in urls {
			let Some(p) = u.parent_url() else { continue };
			if !watched.contains(&p) && !LINKED.read().from_dir(&p).any(|u| watched.contains(u)) {
				continue;
			}
			out_tx.send(u).ok();
			if !parents.contains(&p) {
				out_tx.send(p.clone()).ok();
				parents.insert(p);
			}
		}
	}

	// TODO: performance improvement
	pub(super) fn trigger_dirs(&self, folders: &[&Folder]) {
		let todo: Vec<_> =