redoBranchOperations对路径的判定修正

This commit is contained in:
Xu Chang 2024-12-09 11:22:21 +08:00
parent 42c7365597
commit 41254e9304
5 changed files with 59 additions and 53 deletions

View File

@ -159,7 +159,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
*/
updateItem(lsn: number, data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action']): void;
updateItems(lsn: number, data: Record<string, ED[T]['Update']['data']>, ids: string[], action?: ED[T]['Action']): void;
composeOperations(includeModiBranch?: boolean): Array<{
composeOperations(paths?: string[]): Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}> | undefined;
@ -219,10 +219,10 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
setDirty(): void;
/**
*
* @param includeModiBranch boolean
* @param path operationmodi的前后项
* @returns
*/
composeOperations(includeModiBranch?: boolean): Array<{
composeOperations(paths?: string[]): Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}> | undefined;
@ -257,7 +257,7 @@ declare class VirtualNode<ED extends EntityDict & BaseEntityDict> extends Node<E
destroy(): void;
getFreshValue(): undefined;
refresh(): Promise<void>;
composeOperations(includeModiBranch?: boolean): Array<{
composeOperations(paths?: string[]): Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}> | undefined;
@ -291,7 +291,7 @@ export declare class RunningTree<ED extends EntityDict & BaseEntityDict> extends
private findNode;
destroyNode(path: string, isPage: boolean): void;
begin(): () => void;
redoBranchOperations(path: string, allowInTxn?: boolean): void;
redoBranchOperations(path: string): void;
redoBranchModis(path: string): void;
getFreshValue(path: string): Partial<ED[keyof ED]["Schema"]> | Partial<ED[keyof ED]["Schema"]>[] | undefined;
isDirty(path: string): boolean;

View File

@ -830,14 +830,15 @@ class ListNode extends EntityNode {
ids.forEach((id) => this.updateItemInner(lsn, data, id, action));
this.setDirty();
}
composeOperations(includeModiBranch) {
composeOperations(paths) {
if (!this.dirty) {
return;
}
const intrinsticFilter = this.getIntrinsticFilters();
const ulmLsn = this.ulManager.maxLsn;
paths?.shift();
for (const id in this.children) {
const childOperations = this.children[id].composeOperations(includeModiBranch);
const childOperations = this.children[id].composeOperations(paths);
if (childOperations) {
childOperations.forEach((childOperation) => this.ulManager.push(ulmLsn + 100, childOperation.operation));
}
@ -1320,20 +1321,20 @@ class SingleNode extends EntityNode {
}
/**
*
* @param includeModiBranch 如果显式置了boolean代表只要考虑前项路径或者后项路径
* @param path 如果指定了某条路径则只处理这条路径上的operation区分modi的前后项
* @returns
*/
composeOperations(includeModiBranch) {
composeOperations(paths) {
if (this.dirty) {
const lsnMax = this.ulManager.maxLsn;
const path = paths?.shift();
for (const ele in this.children) {
if (ele.includes(MODI_NEXT_PATH_SUFFIX) && false === includeModiBranch ||
(!ele.includes(MODI_NEXT_PATH_SUFFIX) && true === includeModiBranch)) {
if (path && path !== ele) {
continue;
}
const ele2 = ele.includes(':') ? ele.slice(0, ele.indexOf(':')) : ele;
const child = this.children[ele];
const childOperations = child.composeOperations(includeModiBranch);
const childOperations = child.composeOperations(paths?.length ? paths : undefined);
if (childOperations) {
if (child instanceof SingleNode) {
assert(childOperations.length === 1);
@ -1696,18 +1697,18 @@ class VirtualNode extends Node {
throw err;
}
}
composeOperations(includeModiBranch) {
composeOperations(paths) {
/**
* 当一个virtualNode有多个子结点而这些子结点的前缀一致时标识这些子结点其实是指向同一个对象此时需要合并
*/
const operationss = [];
const operationDict = {};
const path = paths?.shift();
for (const ele in this.children) {
if (ele.includes(MODI_NEXT_PATH_SUFFIX) && false === includeModiBranch ||
(!ele.includes(MODI_NEXT_PATH_SUFFIX) && true === includeModiBranch)) {
if (path && path !== ele) {
continue;
}
const operation = this.children[ele].composeOperations(includeModiBranch);
const operation = this.children[ele].composeOperations(paths?.length ? paths : undefined);
if (operation) {
const idx = ele.indexOf(':') !== -1 ? ele.slice(0, ele.indexOf(':')) : ele;
if (operationDict[idx]) {
@ -1952,10 +1953,11 @@ export class RunningTree extends Feature {
begin() {
return this.cache.begin();
}
redoBranchOperations(path, allowInTxn) {
const { root } = analyzePath(path);
redoBranchOperations(path) {
const paths = path.split('.');
const root = paths.shift();
const rootNode = this.root[root];
const opers = rootNode.composeOperations(path.includes(MODI_NEXT_PATH_SUFFIX));
const opers = rootNode.composeOperations(paths);
if (opers) {
this.cache.redoOperation(opers);
}

View File

@ -159,7 +159,7 @@ declare class ListNode<ED extends EntityDict & BaseEntityDict, T extends keyof E
*/
updateItem(lsn: number, data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action']): void;
updateItems(lsn: number, data: Record<string, ED[T]['Update']['data']>, ids: string[], action?: ED[T]['Action']): void;
composeOperations(includeModiBranch?: boolean): Array<{
composeOperations(paths?: string[]): Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}> | undefined;
@ -219,10 +219,10 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
setDirty(): void;
/**
*
* @param includeModiBranch boolean
* @param path operationmodi的前后项
* @returns
*/
composeOperations(includeModiBranch?: boolean): Array<{
composeOperations(paths?: string[]): Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}> | undefined;
@ -257,7 +257,7 @@ declare class VirtualNode<ED extends EntityDict & BaseEntityDict> extends Node<E
destroy(): void;
getFreshValue(): undefined;
refresh(): Promise<void>;
composeOperations(includeModiBranch?: boolean): Array<{
composeOperations(paths?: string[]): Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}> | undefined;
@ -291,7 +291,7 @@ export declare class RunningTree<ED extends EntityDict & BaseEntityDict> extends
private findNode;
destroyNode(path: string, isPage: boolean): void;
begin(): () => void;
redoBranchOperations(path: string, allowInTxn?: boolean): void;
redoBranchOperations(path: string): void;
redoBranchModis(path: string): void;
getFreshValue(path: string): Partial<ED[keyof ED]["Schema"]> | Partial<ED[keyof ED]["Schema"]>[] | undefined;
isDirty(path: string): boolean;

View File

@ -833,14 +833,15 @@ class ListNode extends EntityNode {
ids.forEach((id) => this.updateItemInner(lsn, data, id, action));
this.setDirty();
}
composeOperations(includeModiBranch) {
composeOperations(paths) {
if (!this.dirty) {
return;
}
const intrinsticFilter = this.getIntrinsticFilters();
const ulmLsn = this.ulManager.maxLsn;
paths?.shift();
for (const id in this.children) {
const childOperations = this.children[id].composeOperations(includeModiBranch);
const childOperations = this.children[id].composeOperations(paths);
if (childOperations) {
childOperations.forEach((childOperation) => this.ulManager.push(ulmLsn + 100, childOperation.operation));
}
@ -1323,20 +1324,20 @@ class SingleNode extends EntityNode {
}
/**
*
* @param includeModiBranch 如果显式置了boolean代表只要考虑前项路径或者后项路径
* @param path 如果指定了某条路径则只处理这条路径上的operation区分modi的前后项
* @returns
*/
composeOperations(includeModiBranch) {
composeOperations(paths) {
if (this.dirty) {
const lsnMax = this.ulManager.maxLsn;
const path = paths?.shift();
for (const ele in this.children) {
if (ele.includes(exports.MODI_NEXT_PATH_SUFFIX) && false === includeModiBranch ||
(!ele.includes(exports.MODI_NEXT_PATH_SUFFIX) && true === includeModiBranch)) {
if (path && path !== ele) {
continue;
}
const ele2 = ele.includes(':') ? ele.slice(0, ele.indexOf(':')) : ele;
const child = this.children[ele];
const childOperations = child.composeOperations(includeModiBranch);
const childOperations = child.composeOperations(paths?.length ? paths : undefined);
if (childOperations) {
if (child instanceof SingleNode) {
(0, assert_1.assert)(childOperations.length === 1);
@ -1699,18 +1700,18 @@ class VirtualNode extends Node {
throw err;
}
}
composeOperations(includeModiBranch) {
composeOperations(paths) {
/**
* 当一个virtualNode有多个子结点而这些子结点的前缀一致时标识这些子结点其实是指向同一个对象此时需要合并
*/
const operationss = [];
const operationDict = {};
const path = paths?.shift();
for (const ele in this.children) {
if (ele.includes(exports.MODI_NEXT_PATH_SUFFIX) && false === includeModiBranch ||
(!ele.includes(exports.MODI_NEXT_PATH_SUFFIX) && true === includeModiBranch)) {
if (path && path !== ele) {
continue;
}
const operation = this.children[ele].composeOperations(includeModiBranch);
const operation = this.children[ele].composeOperations(paths?.length ? paths : undefined);
if (operation) {
const idx = ele.indexOf(':') !== -1 ? ele.slice(0, ele.indexOf(':')) : ele;
if (operationDict[idx]) {
@ -1955,10 +1956,11 @@ class RunningTree extends Feature_1.Feature {
begin() {
return this.cache.begin();
}
redoBranchOperations(path, allowInTxn) {
const { root } = analyzePath(path);
redoBranchOperations(path) {
const paths = path.split('.');
const root = paths.shift();
const rootNode = this.root[root];
const opers = rootNode.composeOperations(path.includes(exports.MODI_NEXT_PATH_SUFFIX));
const opers = rootNode.composeOperations(paths);
if (opers) {
this.cache.redoOperation(opers);
}

View File

@ -1039,7 +1039,7 @@ class ListNode<
this.setDirty();
}
composeOperations(includeModiBranch?: boolean):
composeOperations(paths?: string[]):
| Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation'] }>
| undefined {
if (!this.dirty) {
@ -1049,8 +1049,9 @@ class ListNode<
const intrinsticFilter = this.getIntrinsticFilters();
const ulmLsn = this.ulManager.maxLsn;
paths?.shift();
for (const id in this.children) {
const childOperations = this.children[id].composeOperations(includeModiBranch);
const childOperations = this.children[id].composeOperations(paths);
if (childOperations) {
childOperations.forEach(
(childOperation) => this.ulManager.push(ulmLsn + 100, childOperation.operation as any)
@ -1619,23 +1620,23 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
/**
*
* @param includeModiBranch boolean
* @param path operationmodi的前后项
* @returns
*/
composeOperations(includeModiBranch?: boolean): Array<{
composeOperations(paths?: string[]): Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}> | undefined {
if (this.dirty) {
const lsnMax = this.ulManager.maxLsn;
const path = paths?.shift();
for (const ele in this.children) {
if (ele.includes(MODI_NEXT_PATH_SUFFIX) && false === includeModiBranch ||
(!ele.includes(MODI_NEXT_PATH_SUFFIX) && true === includeModiBranch)) {
if (path && path !== ele) {
continue;
}
const ele2 = ele.includes(':') ? ele.slice(0, ele.indexOf(':')) : ele;
const child = this.children[ele];
const childOperations = child!.composeOperations(includeModiBranch);
const childOperations = child!.composeOperations(paths?.length ? paths : undefined);
if (childOperations) {
if (child instanceof SingleNode) {
assert(childOperations.length === 1);
@ -2031,18 +2032,18 @@ class VirtualNode<ED extends EntityDict & BaseEntityDict> extends Node<ED> {
throw err;
}
}
composeOperations(includeModiBranch?: boolean): Array<{ entity: keyof ED, operation: ED[keyof ED]['Operation'] }> | undefined {
composeOperations(paths?: string[]): Array<{ entity: keyof ED, operation: ED[keyof ED]['Operation'] }> | undefined {
/**
* virtualNode有多个子结点
*/
const operationss = [];
const operationDict: Record<string, any> = {};
const path = paths?.shift();
for (const ele in this.children) {
if (ele.includes(MODI_NEXT_PATH_SUFFIX) && false === includeModiBranch ||
(!ele.includes(MODI_NEXT_PATH_SUFFIX) && true === includeModiBranch)) {
if (path && path !== ele) {
continue;
}
const operation = this.children[ele].composeOperations(includeModiBranch);
const operation = this.children[ele].composeOperations(paths?.length ? paths : undefined);
if (operation) {
const idx = ele.indexOf(':') !== -1 ? ele.slice(0, ele.indexOf(':')) : ele;
if (operationDict[idx]) {
@ -2361,11 +2362,12 @@ export class RunningTree<ED extends EntityDict & BaseEntityDict> extends Feature
return this.cache.begin()!;
}
redoBranchOperations(path: string, allowInTxn?: boolean) {
const { root } = analyzePath(path);
redoBranchOperations(path: string) {
const paths = path.split('.');
const root = paths.shift();
const rootNode = this.root[root];
const opers = rootNode.composeOperations(path.includes(MODI_NEXT_PATH_SUFFIX));
const rootNode = this.root[root!];
const opers = rootNode.composeOperations(paths);
if (opers) {
this.cache.redoOperation(opers);
}