Compare commits

...

2 Commits

3 changed files with 37 additions and 35 deletions

View File

@ -349,7 +349,7 @@ export class Cache extends Feature {
opers.forEach((oper) => { opers.forEach((oper) => {
const { entity, operation } = oper; const { entity, operation } = oper;
this.cacheStore.operate(entity, operation, this.context, { this.cacheStore.operate(entity, operation, this.context, {
checkerTypes: ['logical'], // 这里不能检查data不然在数据没填完前会有大量异常 checkerTypes: ['logical'],
dontCollect: true, dontCollect: true,
}); });
}); });

View File

@ -6,6 +6,7 @@ import { judgeRelation } from "oak-domain/lib/store/relation";
import { Feature } from '../types/Feature'; import { Feature } from '../types/Feature';
import { generateNewId } from 'oak-domain/lib/utils/uuid'; import { generateNewId } from 'oak-domain/lib/utils/uuid';
export const MODI_NEXT_PATH_SUFFIX = ':next'; export const MODI_NEXT_PATH_SUFFIX = ':next';
const START_LSN = 100;
function mergeOperation(schema, entity, oper1, oper2) { function mergeOperation(schema, entity, oper1, oper2) {
const { action, data } = oper2; const { action, data } = oper2;
const operMerged = cloneDeep(oper1); const operMerged = cloneDeep(oper1);
@ -90,7 +91,7 @@ class UpdateLogManager {
constructor(schema, entity, maxLsn) { constructor(schema, entity, maxLsn) {
this.schema = schema, this.schema = schema,
this.entity = entity, this.entity = entity,
this.maxLsn = maxLsn || 0; this.maxLsn = maxLsn || START_LSN;
} }
/** /**
* 合并两个filter完全一致的更新 * 合并两个filter完全一致的更新
@ -165,7 +166,7 @@ class UpdateLogManager {
rollback(lsn) { rollback(lsn) {
const newLogs = this.logs.filter(ele => ele.lsn <= lsn); const newLogs = this.logs.filter(ele => ele.lsn <= lsn);
this.logs = newLogs; this.logs = newLogs;
this.maxLsn = lsn; this.maxLsn = lsn || START_LSN;
} }
makeOperations() { makeOperations() {
const opers = {}; const opers = {};
@ -1431,7 +1432,7 @@ class SingleNode extends Node {
saveRefreshResult(data) { saveRefreshResult(data) {
const ids = Object.keys(data); const ids = Object.keys(data);
assert(ids.length === 1); assert(ids.length === 1);
this.id = ids[0]; this.setId(ids[0]);
this.sr = data[ids[0]]; this.sr = data[ids[0]];
this.passRsToChild(); this.passRsToChild();
// this.publish(); // this.publish();
@ -1743,7 +1744,7 @@ export class RunningTree extends Feature {
this.nodeCountDict = {}; this.nodeCountDict = {};
this.pageNodeStack = {}; this.pageNodeStack = {};
this.singletonDict = {}; this.singletonDict = {};
this.logSerailNumber = 100; this.logSerailNumber = START_LSN;
} }
increaseNodeCount(path) { increaseNodeCount(path) {
if (!this.nodeCountDict[path]) { if (!this.nodeCountDict[path]) {

View File

@ -15,10 +15,11 @@ import { ActionDef } from '../types/Page';
import { generateNewId } from 'oak-domain/lib/utils/uuid'; import { generateNewId } from 'oak-domain/lib/utils/uuid';
export const MODI_NEXT_PATH_SUFFIX = ':next'; export const MODI_NEXT_PATH_SUFFIX = ':next';
const START_LSN = 100;
type LegalOperation<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = ED[T]['CreateSingle'] type LegalOperation<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = ED[T]['CreateSingle']
| ED[T]['Update'] | ED[T]['Update']
| ED[T]['Remove']; | ED[T]['Remove'];
type UpdateLog<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = { type UpdateLog<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
lsn: number; lsn: number;
@ -26,7 +27,7 @@ type UpdateLog<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
}; };
function mergeOperation<ED extends EntityDict & BaseEntityDict, T extends keyof ED> ( function mergeOperation<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(
schema: StorageSchema<ED>, schema: StorageSchema<ED>,
entity: T, entity: T,
oper1: LegalOperation<ED, T>, oper1: LegalOperation<ED, T>,
@ -83,7 +84,7 @@ function mergeOperation<ED extends EntityDict & BaseEntityDict, T extends keyof
dataMerged[attr] = cloneDeep(data[attr]); dataMerged[attr] = cloneDeep(data[attr]);
} }
} }
else if (typeof rel === 'string') { else if (typeof rel === 'string') {
if (dataMerged[attr]) { if (dataMerged[attr]) {
const merged = mergeOperation( const merged = mergeOperation(
schema, schema,
@ -116,7 +117,7 @@ function mergeOperation<ED extends EntityDict & BaseEntityDict, T extends keyof
} }
} }
return operMerged; return operMerged;
} }
/** /**
* *
*/ */
@ -129,8 +130,8 @@ class UpdateLogManager<ED extends EntityDict & BaseEntityDict, T extends keyof E
constructor(schema: StorageSchema<ED>, entity: T, maxLsn?: number) { constructor(schema: StorageSchema<ED>, entity: T, maxLsn?: number) {
this.schema = schema, this.schema = schema,
this.entity = entity, this.entity = entity,
this.maxLsn = maxLsn || 0; this.maxLsn = maxLsn || START_LSN;
} }
/** /**
* filter完全一致的更新 * filter完全一致的更新
@ -213,7 +214,7 @@ class UpdateLogManager<ED extends EntityDict & BaseEntityDict, T extends keyof E
ele => ele.lsn <= lsn ele => ele.lsn <= lsn
); );
this.logs = newLogs; this.logs = newLogs;
this.maxLsn = lsn; this.maxLsn = lsn || START_LSN;
} }
makeOperations() { makeOperations() {
@ -981,7 +982,7 @@ class ListNode<
undefinedAttrs.push(k); undefinedAttrs.push(k);
} }
} }
undefinedAttrs.forEach( undefinedAttrs.forEach(
(attr) => unset(data, attr) (attr) => unset(data, attr)
); );
@ -1017,16 +1018,16 @@ class ListNode<
if (childOperations) { if (childOperations) {
childOperations.forEach( childOperations.forEach(
(childOperation) => this.ulManager.push(ulmLsn + 100, childOperation.operation as any) (childOperation) => this.ulManager.push(ulmLsn + 100, childOperation.operation as any)
); );
} }
} }
const operations = this.ulManager.makeOperations(); const operations = this.ulManager.makeOperations();
this.ulManager.rollback(ulmLsn); this.ulManager.rollback(ulmLsn);
return operations.map( return operations.map(
(operation) => { (operation) => {
const { filter, ...rest} = operation; const { filter, ...rest } = operation;
return { return {
entity: this.entity, entity: this.entity,
operation: { operation: {
@ -1389,7 +1390,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
if (id !== this.id) { if (id !== this.id) {
const operations = this.ulManager.makeOperations(); const operations = this.ulManager.makeOperations();
assert(operations.length <= 1); assert(operations.length <= 1);
const [ operation ] = operations; const [operation] = operations;
// 如果本身是create 这里无视就行(因为框架原因会调用一次) // 如果本身是create 这里无视就行(因为框架原因会调用一次)
if (operation?.action === 'create') { if (operation?.action === 'create') {
if (operation.data.id === id) { if (operation.data.id === id) {
@ -1417,7 +1418,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
} }
const operations = this.ulManager.makeOperations(); const operations = this.ulManager.makeOperations();
assert(operations.length <= 1); assert(operations.length <= 1);
const [ operation ] = operations; const [operation] = operations;
if (operation && operation?.action === 'create') { if (operation && operation?.action === 'create') {
return operation.data.id; return operation.data.id;
} }
@ -1506,14 +1507,14 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
(attr) => unset(data, attr) (attr) => unset(data, attr)
); );
this.ulManager.push(lsn, { this.ulManager.push(lsn, {
action: action || 'update', action: action || 'update',
data, data,
filter: { filter: {
id: this.getId()!, id: this.getId()!,
} }
} as unknown as Omit<ED[T]['Operation'], "id">); } as unknown as Omit<ED[T]['Operation'], "id">);
// 处理外键如果update的数据中有相应的外键其子对象上的动作应当被clean掉 // 处理外键如果update的数据中有相应的外键其子对象上的动作应当被clean掉
// 并将sr传递到子组件上 // 并将sr传递到子组件上
@ -1544,7 +1545,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
action: 'remove', action: 'remove',
data: {}, data: {},
filter: { filter: {
id, id,
} }
} as unknown as Omit<ED[T]['Remove'], "id">); } as unknown as Omit<ED[T]['Remove'], "id">);
@ -1558,7 +1559,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
action: 'update', action: 'update',
data: {}, data: {},
filter: { filter: {
id, id,
} }
} as unknown as Omit<ED[T]['Update'], "id">); } as unknown as Omit<ED[T]['Update'], "id">);
super.setDirty(); super.setDirty();
@ -1579,7 +1580,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
assert(childOperations.length === 1); assert(childOperations.length === 1);
this.ulManager.push(lsnMax + 100, { this.ulManager.push(lsnMax + 100, {
action: 'update', action: 'update',
data: { data: {
[ele2]: childOperations[0].operation, [ele2]: childOperations[0].operation,
}, },
filter: { filter: {
@ -1594,7 +1595,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
data: { data: {
[ele2]: childOperations.map( [ele2]: childOperations.map(
({ operation }) => operation ({ operation }) => operation
), ),
}, },
filter: { filter: {
id: this.getId(), id: this.getId(),
@ -1607,12 +1608,12 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
this.ulManager.rollback(lsnMax); this.ulManager.rollback(lsnMax);
assert(operations.length <= 1); assert(operations.length <= 1);
const [ operation ] = operations; const [operation] = operations;
if (operation) { if (operation) {
const { filter, ...rest } = operation; const { filter, ...rest } = operation;
const intrinsticFilter = this.getIntrinsticFilters(); const intrinsticFilter = this.getIntrinsticFilters();
return [ return [
{ {
entity: this.entity, entity: this.entity,
@ -1728,7 +1729,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
saveRefreshResult(data: Record<string, any>) { saveRefreshResult(data: Record<string, any>) {
const ids = Object.keys(data); const ids = Object.keys(data);
assert(ids.length === 1); assert(ids.length === 1);
this.id = ids[0]; this.setId(ids[0]);
this.sr = data[ids[0]!]; this.sr = data[ids[0]!];
this.passRsToChild(); this.passRsToChild();
@ -1784,7 +1785,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
private getFilter(): ED[T]['Selection']['filter'] | undefined { private getFilter(): ED[T]['Selection']['filter'] | undefined {
// 如果是新建等于没有filter // 如果是新建等于没有filter
const [ operation ] = this.ulManager.makeOperations(); const [operation] = this.ulManager.makeOperations();
if (operation?.action === 'create') { if (operation?.action === 'create') {
return; return;
} }
@ -2022,7 +2023,7 @@ class VirtualNode<ED extends EntityDict & BaseEntityDict> extends Feature {
for (const ele in this.children) { for (const ele in this.children) {
this.children[ele].clean(lsn, dontPublish); this.children[ele].clean(lsn, dontPublish);
} }
if (!lsn) { if (!lsn) {
this.dirty = false; this.dirty = false;
} }
@ -2107,7 +2108,7 @@ export class RunningTree<ED extends EntityDict & BaseEntityDict> extends Feature
this.nodeCountDict = {}; this.nodeCountDict = {};
this.pageNodeStack = {}; this.pageNodeStack = {};
this.singletonDict = {}; this.singletonDict = {};
this.logSerailNumber = 100; this.logSerailNumber = START_LSN;
} }
private increaseNodeCount(path: string) { private increaseNodeCount(path: string) {
@ -2799,10 +2800,10 @@ export class RunningTree<ED extends EntityDict & BaseEntityDict> extends Feature
throw err; throw err;
} }
} }
savePoint() { savePoint() {
const lsn = this.logSerailNumber; const lsn = this.logSerailNumber;
this.logSerailNumber ++; this.logSerailNumber++;
return lsn; return lsn;
} }
@ -2812,7 +2813,7 @@ export class RunningTree<ED extends EntityDict & BaseEntityDict> extends Feature
* @param lsn savepoint * @param lsn savepoint
* @param dontPublish * @param dontPublish
*/ */
clean(path: string, lsn?:number, dontPublish?: true) { clean(path: string, lsn?: number, dontPublish?: true) {
const node = this.findNode(path)!; const node = this.findNode(path)!;
node.clean(lsn, dontPublish); node.clean(lsn, dontPublish);