Skip to main content

OcrQueue

Struct OcrQueue 

Source
pub struct OcrQueue { /* private fields */ }
Expand description

OCR 队列:图片的 (path,mtime,size) 待处理表 + 已处理结果缓存,随索引目录持久化 在 <index_dir>-ocr-queue.json(跟 meta.rs 的 <index_dir>-meta.json 同一个 “索引目录旁的兄弟文件“套路,不塞进 tantivy 自己管理的索引目录里)。

进程内按 index_dir 单例复用(见 for_index_dir):rebuild_index、reconcile、 增量更新(IndexUpdater::apply)、OCR worker 池,这四处调用方全部共享同一份 内存状态。如果各自独立开一份再各自落盘,后写的会把先写的进度覆盖掉—— 队列持久化的意义就没了。

Implementations§

Source§

impl OcrQueue

Source

pub fn for_index_dir(index_dir: &Path) -> Arc<OcrQueue>

取(或首次创建)某个索引目录对应的进程内单例。第一次调用时从磁盘加载已持久化 的状态;磁盘上没有(旧索引、或者这是第一次跑 M4 之后的代码)就是空队列,不算错误。

不变量:单例注册表按规范化后的路径(剥掉 \\?\/\\?\UNC\ 扩展长度 前缀,见 crate::display_path)去重。同一个索引目录可能被不同调用方 用不同的路径语法传进来——比如 E:\indexPath::canonicalize() 在 Windows 上天生带前缀的 \\?\E:\index,两者指向磁盘上同一个目录。如果 key 原样比较,会各建出一份独立的 OcrQueue,谁后 save() 就把谁的 进度覆盖掉。只有 map 的 key 做规范化;存进单例本体、参与文件 IO 的 index_dir 字段仍然是第一次创建它的调用方传入的原始路径——长路径场景 要靠 \\?\ 前缀绕开 Win32 MAX_PATH,不能剥。

Source

pub fn pending_len(&self) -> usize

待处理项数,给 CLI 的 drain_ocr_queue 判断“清空了没“用。

Source

pub fn save(&self) -> Result<()>

落盘。rebuild_index/reconcile 批量入队后各调一次;IndexUpdater::apply 在 一批增量里确实碰到过图片时也调一次;worker 每处理完一张图也调一次—— 一次 JSON 序列化的代价远小于一次 OCR 识别(百毫秒级),可以接受。

Source

pub fn compact(&self, roots: &[PathBuf])

按当前扫描根裁剪队列:不落在 roots 任一根之下、或者对应文件已经不在 磁盘上的 pending/processed 条目一律丢弃。

这个队列是进程级单例(见 Self::for_index_dir),rebuild_index 每次 全量重建时会把内存里已有的历史条目原样存回——如果目标目录换过、或者 有文件在两次重建之间被删掉,这些条目没有任何清理路径,只增不减、永久 堆积。rebuild_index 在最终落盘前调用这个方法压实一次。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Fruit for T
where T: Send + Downcast,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.