跳到主要内容

captureChanges()

function captureChanges(
executor,
host,
options
): Promise<number>;

Defined in: packages/rxdb-plugin-working-tree/src/working-tree/capture-runtime.ts:539

把一批变更日志捕获成工作树单元(整批共享一个 unitId)

Parameters​

ParameterTypeDescription
executorTransactionExecutor业务写所在的那个事务
hostWorkingTreeCaptureHost造实例用的实体管理器宿主
options{ changes: readonly ChangeCaptureSource[]; origin: WriteEntryOrigin; shouldCapture: (change) => boolean; token: ActiveBranchToken; unitId: string; }令牌、来源与变更列表
options.changesreadonly ChangeCaptureSource[]待捕获的变更日志
options.originWriteEntryOrigin单元来源
options.shouldCapture(change) => boolean该实体要不要进工作树;untracked 域在这里被挡掉
options.tokenActiveBranchToken本次写持有的 active 分支令牌
options.unitIdstring整批共享的单元 id

Returns​

Promise<number>

实际落成单元的条数(被 CaptureFilter 挡掉的不计)

Remarks​

一次写原语一个 unitId(adapter-contract.md §5「完整事务的全部实体共享同一个 unitId」): 每行各发一个的话,部分恢复会把一个原子操作劈成两半。

逐行 await,不 Promise.all:折叠要读同一张表的既有行,并发跑会让两条写同一实体的变更 各自读到「还没有这一行」,然后双双 create 撞唯一索引。

整批共用一个 WorkingTreeCaptureBatch:令牌与状态行于是各读一次,而不是每条变更各读一次。 一批 M 条变更的查询数因此从 7M 落到 2M + 3——这是整个插件里唯一按用户写入频率跑的一段, 一次批量导入 500 行时那个系数直接乘在 500 上。