mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
add option to ignore pre-caching tasks
This commit is contained in:
parent
dc1649f9ba
commit
04316e6242
6 changed files with 43 additions and 3 deletions
|
|
@ -71,6 +71,7 @@ macro_workers = 10
|
||||||
bizarre_retry = 5
|
bizarre_retry = 5
|
||||||
image_alloc = 536870912 # 512MB
|
image_alloc = 536870912 # 512MB
|
||||||
image_bound = [ 0, 0 ]
|
image_bound = [ 0, 0 ]
|
||||||
|
ignore_precaching_tasks = true
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
preload = []
|
preload = []
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ pub struct Tasks {
|
||||||
|
|
||||||
pub image_alloc: u32,
|
pub image_alloc: u32,
|
||||||
pub image_bound: [u16; 2],
|
pub image_bound: [u16; 2],
|
||||||
|
|
||||||
|
pub ignore_precaching_tasks: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Tasks {
|
impl Default for Tasks {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{cmp::Ordering, collections::BTreeMap, mem};
|
use std::{cmp::Ordering, collections::BTreeMap, mem};
|
||||||
|
|
||||||
use yazi_config::manager::SortBy;
|
use yazi_config::manager::SortBy;
|
||||||
use yazi_shared::{fs::File, fs::Url, natsort};
|
use yazi_shared::{fs::{File, Url}, natsort};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, PartialEq)]
|
#[derive(Clone, Copy, Default, PartialEq)]
|
||||||
pub struct FilesSorter {
|
pub struct FilesSorter {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
|
use yazi_config::TASKS;
|
||||||
|
|
||||||
use super::{Task, TaskStage};
|
use super::{Task, TaskStage};
|
||||||
|
use crate::TaskKind;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Running {
|
pub struct Running {
|
||||||
|
|
@ -36,7 +38,14 @@ impl Running {
|
||||||
pub(super) fn exists(&self, id: usize) -> bool { self.all.contains_key(&id) }
|
pub(super) fn exists(&self, id: usize) -> bool { self.all.contains_key(&id) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn values(&self) -> impl Iterator<Item = &Task> { self.all.values() }
|
pub fn values(&self) -> impl Iterator<Item = &Task> {
|
||||||
|
let map = self.all.values();
|
||||||
|
if TASKS.ignore_precaching_tasks {
|
||||||
|
map.into_iter().filter(|t| t.kind == TaskKind::User).collect::<Vec<_>>().into_iter()
|
||||||
|
} else {
|
||||||
|
map.into_iter().collect::<Vec<_>>().into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_empty(&self) -> bool { self.all.is_empty() }
|
pub fn is_empty(&self) -> bool { self.all.is_empty() }
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use yazi_config::{open::Opener, TASKS};
|
||||||
use yazi_shared::{emit, event::Exec, fs::{unique_path, Url}, Layer, Throttle};
|
use yazi_shared::{emit, event::Exec, fs::{unique_path, Url}, Layer, Throttle};
|
||||||
|
|
||||||
use super::{Running, TaskOp, TaskStage};
|
use super::{Running, TaskOp, TaskStage};
|
||||||
use crate::workers::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash, Precache, PrecacheOpMime, PrecacheOpSize, Process, ProcessOpOpen};
|
use crate::{workers::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash, Precache, PrecacheOpMime, PrecacheOpSize, Process, ProcessOpOpen}, TaskKind};
|
||||||
|
|
||||||
pub struct Scheduler {
|
pub struct Scheduler {
|
||||||
file: Arc<File>,
|
file: Arc<File>,
|
||||||
|
|
@ -336,6 +336,10 @@ impl Scheduler {
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = running.add(format!("Calculate the size of {:?}", target));
|
let id = running.add(format!("Calculate the size of {:?}", target));
|
||||||
|
if let Some(task) = self.running.clone().write().get_mut(id) {
|
||||||
|
task.kind = TaskKind::PreCache;
|
||||||
|
}
|
||||||
|
|
||||||
_ = self.todo.send_blocking({
|
_ = self.todo.send_blocking({
|
||||||
let precache = self.precache.clone();
|
let precache = self.precache.clone();
|
||||||
let target = target.clone();
|
let target = target.clone();
|
||||||
|
|
@ -352,6 +356,10 @@ impl Scheduler {
|
||||||
let name = format!("Preload mimetype for {} files", targets.len());
|
let name = format!("Preload mimetype for {} files", targets.len());
|
||||||
let id = self.running.write().add(name);
|
let id = self.running.write().add(name);
|
||||||
|
|
||||||
|
if let Some(task) = self.running.clone().write().get_mut(id) {
|
||||||
|
task.kind = TaskKind::PreCache;
|
||||||
|
}
|
||||||
|
|
||||||
_ = self.todo.send_blocking({
|
_ = self.todo.send_blocking({
|
||||||
let precache = self.precache.clone();
|
let precache = self.precache.clone();
|
||||||
async move {
|
async move {
|
||||||
|
|
@ -365,6 +373,10 @@ impl Scheduler {
|
||||||
let name = format!("Precache of {} image files", targets.len());
|
let name = format!("Precache of {} image files", targets.len());
|
||||||
let id = self.running.write().add(name);
|
let id = self.running.write().add(name);
|
||||||
|
|
||||||
|
if let Some(task) = self.running.clone().write().get_mut(id) {
|
||||||
|
task.kind = TaskKind::PreCache;
|
||||||
|
}
|
||||||
|
|
||||||
self.precache.image(id, targets).ok();
|
self.precache.image(id, targets).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -372,6 +384,10 @@ impl Scheduler {
|
||||||
let name = format!("Precache of {} video files", targets.len());
|
let name = format!("Precache of {} video files", targets.len());
|
||||||
let id = self.running.write().add(name);
|
let id = self.running.write().add(name);
|
||||||
|
|
||||||
|
if let Some(task) = self.running.clone().write().get_mut(id) {
|
||||||
|
task.kind = TaskKind::PreCache;
|
||||||
|
}
|
||||||
|
|
||||||
self.precache.video(id, targets).ok();
|
self.precache.video(id, targets).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,6 +395,10 @@ impl Scheduler {
|
||||||
let name = format!("Precache of {} PDF files", targets.len());
|
let name = format!("Precache of {} PDF files", targets.len());
|
||||||
let id = self.running.write().add(name);
|
let id = self.running.write().add(name);
|
||||||
|
|
||||||
|
if let Some(task) = self.running.clone().write().get_mut(id) {
|
||||||
|
task.kind = TaskKind::PreCache;
|
||||||
|
}
|
||||||
|
|
||||||
self.precache.pdf(id, targets).ok();
|
self.precache.pdf(id, targets).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ pub struct Task {
|
||||||
pub id: usize,
|
pub id: usize,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub stage: TaskStage,
|
pub stage: TaskStage,
|
||||||
|
pub kind: TaskKind,
|
||||||
|
|
||||||
pub total: u32,
|
pub total: u32,
|
||||||
pub succ: u32,
|
pub succ: u32,
|
||||||
|
|
@ -69,3 +70,10 @@ pub enum TaskStage {
|
||||||
Dispatched,
|
Dispatched,
|
||||||
Hooked,
|
Hooked,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
|
pub enum TaskKind {
|
||||||
|
#[default]
|
||||||
|
User,
|
||||||
|
PreCache,
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue