mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
903850935f
commit
6066f1e382
3 changed files with 20 additions and 14 deletions
|
|
@ -98,8 +98,7 @@ impl Manager {
|
|||
}
|
||||
|
||||
if !succeeded.is_empty() {
|
||||
// Pubsub::pub_from_bulk(tab, &changes);
|
||||
|
||||
Pubsub::pub_from_bulk(tab, succeeded.iter().map(|(u, f)| (u, &f.url)).collect());
|
||||
FilesOp::Upserting(cwd, succeeded).emit();
|
||||
}
|
||||
drop(permit);
|
||||
|
|
|
|||
|
|
@ -9,20 +9,27 @@ use super::Body;
|
|||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct BodyBulk<'a> {
|
||||
pub tab: usize,
|
||||
pub changes: Cow<'a, HashMap<Url, Url>>,
|
||||
pub changes: HashMap<Cow<'a, Url>, Cow<'a, Url>>,
|
||||
}
|
||||
|
||||
impl<'a> BodyBulk<'a> {
|
||||
#[inline]
|
||||
pub fn borrowed(tab: usize, changes: &'a HashMap<Url, Url>) -> Body<'a> {
|
||||
Self { tab, changes: Cow::Borrowed(changes) }.into()
|
||||
pub fn borrowed(tab: usize, changes: &HashMap<&'a Url, &'a Url>) -> Body<'a> {
|
||||
let iter = changes.iter().map(|(&from, &to)| (Cow::Borrowed(from), Cow::Borrowed(to)));
|
||||
|
||||
Self { tab, changes: iter.collect() }.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl BodyBulk<'static> {
|
||||
#[inline]
|
||||
pub fn owned(tab: usize, changes: &HashMap<Url, Url>) -> Body<'static> {
|
||||
Self { tab, changes: Cow::Owned(changes.clone()) }.into()
|
||||
pub fn owned(tab: usize, changes: &HashMap<&Url, &Url>) -> Body<'static> {
|
||||
let changes = changes
|
||||
.iter()
|
||||
.map(|(&from, &to)| (Cow::Owned(from.clone()), Cow::Owned(to.clone())))
|
||||
.collect();
|
||||
|
||||
Self { tab, changes }.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,14 +39,14 @@ impl<'a> From<BodyBulk<'a>> for Body<'a> {
|
|||
|
||||
impl IntoLua<'_> for BodyBulk<'static> {
|
||||
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
|
||||
BodyBulkIter { tab: self.tab, inner: self.changes.into_owned().into_iter() }.into_lua(lua)
|
||||
BodyBulkIter { tab: self.tab, inner: self.changes.into_iter() }.into_lua(lua)
|
||||
}
|
||||
}
|
||||
|
||||
// --- Iterator
|
||||
pub struct BodyBulkIter {
|
||||
pub tab: usize,
|
||||
pub inner: hash_map::IntoIter<Url, Url>,
|
||||
pub inner: hash_map::IntoIter<Cow<'static, Url>, Cow<'static, Url>>,
|
||||
}
|
||||
|
||||
impl UserData for BodyBulkIter {
|
||||
|
|
@ -52,7 +59,7 @@ impl UserData for BodyBulkIter {
|
|||
|
||||
methods.add_meta_function(MetaMethod::Pairs, |lua, me: AnyUserData| {
|
||||
let iter = lua.create_function(|lua, mut me: UserDataRefMut<Self>| {
|
||||
if let Some((from, to)) = me.inner.next() {
|
||||
if let Some((Cow::Owned(from), Cow::Owned(to))) = me.inner.next() {
|
||||
(lua.create_any_userdata(from)?, lua.create_any_userdata(to)?).into_lua_multi(lua)
|
||||
} else {
|
||||
().into_lua_multi(lua)
|
||||
|
|
|
|||
|
|
@ -130,15 +130,15 @@ impl Pubsub {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pub_from_bulk(tab: usize, changes: &HashMap<Url, Url>) {
|
||||
pub fn pub_from_bulk(tab: usize, changes: HashMap<&Url, &Url>) {
|
||||
if LOCAL.read().contains_key("bulk") {
|
||||
Self::pub_(BodyBulk::owned(tab, changes));
|
||||
Self::pub_(BodyBulk::owned(tab, &changes));
|
||||
}
|
||||
if PEERS.read().values().any(|p| p.able("bulk")) {
|
||||
Client::push(BodyBulk::borrowed(tab, changes));
|
||||
Client::push(BodyBulk::borrowed(tab, &changes));
|
||||
}
|
||||
if BOOT.local_events.contains("bulk") {
|
||||
BodyBulk::borrowed(tab, changes).with_receiver(*ID).flush();
|
||||
BodyBulk::borrowed(tab, &changes).with_receiver(*ID).flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue