调整对cache取数据时,属性缺失下的行为
This commit is contained in:
parent
1870f74dcc
commit
f03f1d5e8d
|
|
@ -21,7 +21,7 @@ type RefreshOption = {
|
|||
};
|
||||
type WholeAspectDict<ED extends EntityDict & BaseEntityDict, AD extends Record<string, Aspect<ED, AsyncContext<ED>>>> = CommonAspectDict<ED> & AD;
|
||||
export declare class Cache<ED extends EntityDict & BaseEntityDict> extends Feature {
|
||||
cacheStore: CacheStore<ED>;
|
||||
private cacheStore;
|
||||
private syncEventsCallbacks;
|
||||
private contextBuilder;
|
||||
private refreshing;
|
||||
|
|
@ -130,10 +130,7 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict> extends Featu
|
|||
* @param sr
|
||||
*/
|
||||
mergeSelectResult<T extends keyof ED>(entity: T, rows: Partial<ED[T]['Schema']>[], sr: Record<string, any>): void;
|
||||
get<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], option?: {
|
||||
accurate?: true;
|
||||
allowMiss?: boolean;
|
||||
}, sr?: Record<string, any>): Partial<ED[T]["Schema"]>[];
|
||||
get<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], sr?: Record<string, any>): Partial<ED[T]["Schema"]>[];
|
||||
judgeRelation(entity: keyof ED, attr: string): string | 0 | 1 | string[] | 2 | -1;
|
||||
bindOnSync(callback: (opRecords: OpRecord<ED>[]) => void): void;
|
||||
unbindOnSync(callback: (opRecords: OpRecord<ED>[]) => void): void;
|
||||
|
|
|
|||
|
|
@ -222,8 +222,7 @@ export class Cache extends Feature {
|
|||
indexFrom: undefined,
|
||||
count: undefined,
|
||||
});
|
||||
// 因为能确保满足条件的行都取出来了,这里可以加上allowMiss,否则可能cache中一些不完整的行会触发fetchRow by Xc 20241207
|
||||
const data = this.get(entity, selection2, { allowMiss: true, accurate: true }, sr);
|
||||
const data = this.get(entity, selection2, sr);
|
||||
if (useLocalCache) {
|
||||
this.saveRefreshRecord(entity);
|
||||
}
|
||||
|
|
@ -435,29 +434,19 @@ export class Cache extends Feature {
|
|||
});
|
||||
}
|
||||
}
|
||||
getInner(entity, selection, option) {
|
||||
getInner(entity, selection) {
|
||||
const rollback = this.begin(true);
|
||||
try {
|
||||
const result = this.cacheStore.select(entity, selection, this.context, {
|
||||
dontCollect: true,
|
||||
includedDeleted: true,
|
||||
ignoreAttrMiss: option?.allowMiss || undefined,
|
||||
obscure: !option?.accurate,
|
||||
});
|
||||
rollback && rollback();
|
||||
return result;
|
||||
}
|
||||
catch (err) {
|
||||
rollback && rollback();
|
||||
if (err instanceof OakRowUnexistedException) {
|
||||
if (!option?.allowMiss) {
|
||||
this.fetchRows(err.getRows());
|
||||
}
|
||||
return [];
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
@ -499,8 +488,8 @@ export class Cache extends Feature {
|
|||
}
|
||||
});
|
||||
}
|
||||
get(entity, selection, option, sr) {
|
||||
const rows = this.getInner(entity, selection, option);
|
||||
get(entity, selection, sr) {
|
||||
const rows = this.getInner(entity, selection);
|
||||
if (sr) {
|
||||
this.mergeSelectResult(entity, rows, sr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ export default class Console extends Feature {
|
|||
}
|
||||
},
|
||||
}
|
||||
}, { accurate: true });
|
||||
});
|
||||
this.availMenus.forEach((menu) => {
|
||||
let { destEntity, path, actions, sourceEntity } = menu;
|
||||
let available = false;
|
||||
|
|
|
|||
|
|
@ -726,7 +726,7 @@ class ListNode extends EntityNode {
|
|||
data,
|
||||
filter: inModi ? filter : filter2,
|
||||
sorter,
|
||||
}, undefined, this.sr);
|
||||
}, this.sr);
|
||||
return result;
|
||||
}
|
||||
return [];
|
||||
|
|
@ -1227,7 +1227,7 @@ class SingleNode extends EntityNode {
|
|||
filter: {
|
||||
id,
|
||||
},
|
||||
}, undefined, {
|
||||
}, {
|
||||
[id]: this.sr,
|
||||
});
|
||||
return result[0];
|
||||
|
|
@ -1454,8 +1454,6 @@ class SingleNode extends EntityNode {
|
|||
filter: {
|
||||
id: this.id,
|
||||
},
|
||||
}, {
|
||||
allowMiss: true,
|
||||
}, this.sr);
|
||||
const keys = k ? [k] : Object.keys(this.children || {});
|
||||
for (const k of keys) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ type RefreshOption = {
|
|||
};
|
||||
type WholeAspectDict<ED extends EntityDict & BaseEntityDict, AD extends Record<string, Aspect<ED, AsyncContext<ED>>>> = CommonAspectDict<ED> & AD;
|
||||
export declare class Cache<ED extends EntityDict & BaseEntityDict> extends Feature {
|
||||
cacheStore: CacheStore<ED>;
|
||||
private cacheStore;
|
||||
private syncEventsCallbacks;
|
||||
private contextBuilder;
|
||||
private refreshing;
|
||||
|
|
@ -130,10 +130,7 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict> extends Featu
|
|||
* @param sr
|
||||
*/
|
||||
mergeSelectResult<T extends keyof ED>(entity: T, rows: Partial<ED[T]['Schema']>[], sr: Record<string, any>): void;
|
||||
get<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], option?: {
|
||||
accurate?: true;
|
||||
allowMiss?: boolean;
|
||||
}, sr?: Record<string, any>): Partial<ED[T]["Schema"]>[];
|
||||
get<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], sr?: Record<string, any>): Partial<ED[T]["Schema"]>[];
|
||||
judgeRelation(entity: keyof ED, attr: string): string | 0 | 1 | string[] | 2 | -1;
|
||||
bindOnSync(callback: (opRecords: OpRecord<ED>[]) => void): void;
|
||||
unbindOnSync(callback: (opRecords: OpRecord<ED>[]) => void): void;
|
||||
|
|
|
|||
|
|
@ -225,8 +225,7 @@ class Cache extends Feature_1.Feature {
|
|||
indexFrom: undefined,
|
||||
count: undefined,
|
||||
});
|
||||
// 因为能确保满足条件的行都取出来了,这里可以加上allowMiss,否则可能cache中一些不完整的行会触发fetchRow by Xc 20241207
|
||||
const data = this.get(entity, selection2, { allowMiss: true, accurate: true }, sr);
|
||||
const data = this.get(entity, selection2, sr);
|
||||
if (useLocalCache) {
|
||||
this.saveRefreshRecord(entity);
|
||||
}
|
||||
|
|
@ -438,29 +437,19 @@ class Cache extends Feature_1.Feature {
|
|||
});
|
||||
}
|
||||
}
|
||||
getInner(entity, selection, option) {
|
||||
getInner(entity, selection) {
|
||||
const rollback = this.begin(true);
|
||||
try {
|
||||
const result = this.cacheStore.select(entity, selection, this.context, {
|
||||
dontCollect: true,
|
||||
includedDeleted: true,
|
||||
ignoreAttrMiss: option?.allowMiss || undefined,
|
||||
obscure: !option?.accurate,
|
||||
});
|
||||
rollback && rollback();
|
||||
return result;
|
||||
}
|
||||
catch (err) {
|
||||
rollback && rollback();
|
||||
if (err instanceof Exception_1.OakRowUnexistedException) {
|
||||
if (!option?.allowMiss) {
|
||||
this.fetchRows(err.getRows());
|
||||
}
|
||||
return [];
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
@ -502,8 +491,8 @@ class Cache extends Feature_1.Feature {
|
|||
}
|
||||
});
|
||||
}
|
||||
get(entity, selection, option, sr) {
|
||||
const rows = this.getInner(entity, selection, option);
|
||||
get(entity, selection, sr) {
|
||||
const rows = this.getInner(entity, selection);
|
||||
if (sr) {
|
||||
this.mergeSelectResult(entity, rows, sr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ class Console extends Feature_1.Feature {
|
|||
}
|
||||
},
|
||||
}
|
||||
}, { accurate: true });
|
||||
});
|
||||
this.availMenus.forEach((menu) => {
|
||||
let { destEntity, path, actions, sourceEntity } = menu;
|
||||
let available = false;
|
||||
|
|
|
|||
|
|
@ -729,7 +729,7 @@ class ListNode extends EntityNode {
|
|||
data,
|
||||
filter: inModi ? filter : filter2,
|
||||
sorter,
|
||||
}, undefined, this.sr);
|
||||
}, this.sr);
|
||||
return result;
|
||||
}
|
||||
return [];
|
||||
|
|
@ -1230,7 +1230,7 @@ class SingleNode extends EntityNode {
|
|||
filter: {
|
||||
id,
|
||||
},
|
||||
}, undefined, {
|
||||
}, {
|
||||
[id]: this.sr,
|
||||
});
|
||||
return result[0];
|
||||
|
|
@ -1457,8 +1457,6 @@ class SingleNode extends EntityNode {
|
|||
filter: {
|
||||
id: this.id,
|
||||
},
|
||||
}, {
|
||||
allowMiss: true,
|
||||
}, this.sr);
|
||||
const keys = k ? [k] : Object.keys(this.children || {});
|
||||
for (const k of keys) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ type RefreshOption = {
|
|||
type WholeAspectDict<ED extends EntityDict & BaseEntityDict, AD extends Record<string, Aspect<ED, AsyncContext<ED>>>> = CommonAspectDict<ED> & AD;
|
||||
|
||||
export class Cache<ED extends EntityDict & BaseEntityDict> extends Feature {
|
||||
cacheStore: CacheStore<ED>;
|
||||
private cacheStore: CacheStore<ED>;
|
||||
private syncEventsCallbacks: Array<
|
||||
(opRecords: OpRecord<ED>[]) => void
|
||||
>;
|
||||
|
|
@ -323,8 +323,7 @@ export class Cache<ED extends EntityDict & BaseEntityDict> extends Feature {
|
|||
indexFrom: undefined,
|
||||
count: undefined,
|
||||
});
|
||||
// 因为能确保满足条件的行都取出来了,这里可以加上allowMiss,否则可能cache中一些不完整的行会触发fetchRow by Xc 20241207
|
||||
const data = this.get(entity, selection2, { allowMiss: true, accurate: true }, sr);
|
||||
const data = this.get(entity, selection2, sr);
|
||||
if (useLocalCache) {
|
||||
this.saveRefreshRecord(entity);
|
||||
}
|
||||
|
|
@ -587,11 +586,7 @@ export class Cache<ED extends EntityDict & BaseEntityDict> extends Feature {
|
|||
|
||||
private getInner<T extends keyof ED>(
|
||||
entity: T,
|
||||
selection: ED[T]['Selection'],
|
||||
option?: {
|
||||
allowMiss?: boolean,
|
||||
accurate?: true;
|
||||
}): Partial<ED[T]['Schema']>[] {
|
||||
selection: ED[T]['Selection']): Partial<ED[T]['Schema']>[] {
|
||||
const rollback = this.begin(true);
|
||||
try {
|
||||
const result = this.cacheStore!.select(
|
||||
|
|
@ -601,22 +596,13 @@ export class Cache<ED extends EntityDict & BaseEntityDict> extends Feature {
|
|||
{
|
||||
dontCollect: true,
|
||||
includedDeleted: true,
|
||||
ignoreAttrMiss: option?.allowMiss || undefined,
|
||||
obscure: !option?.accurate,
|
||||
}
|
||||
);
|
||||
rollback && rollback();
|
||||
return result;
|
||||
} catch (err) {
|
||||
rollback && rollback();
|
||||
if (err instanceof OakRowUnexistedException) {
|
||||
if (!option?.allowMiss) {
|
||||
this.fetchRows(err.getRows());
|
||||
}
|
||||
return [];
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -666,13 +652,9 @@ export class Cache<ED extends EntityDict & BaseEntityDict> extends Feature {
|
|||
get<T extends keyof ED>(
|
||||
entity: T,
|
||||
selection: ED[T]['Selection'],
|
||||
option?: {
|
||||
accurate?: true;
|
||||
allowMiss?: boolean;
|
||||
},
|
||||
sr?: Record<string, any>,
|
||||
) {
|
||||
const rows = this.getInner(entity, selection, option);
|
||||
const rows = this.getInner(entity, selection);
|
||||
|
||||
if (sr) {
|
||||
this.mergeSelectResult(entity, rows, sr);
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ export default abstract class Console<ED extends EntityDict & BaseEntityDict, OM
|
|||
}
|
||||
},
|
||||
}
|
||||
}, { accurate: true });
|
||||
});
|
||||
|
||||
this.availMenus.forEach(
|
||||
(menu) => {
|
||||
|
|
|
|||
|
|
@ -894,7 +894,7 @@ class ListNode<
|
|||
data,
|
||||
filter: inModi ? filter : filter2,
|
||||
sorter,
|
||||
}, undefined, this.sr);
|
||||
}, this.sr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1513,7 +1513,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
filter: {
|
||||
id,
|
||||
},
|
||||
}, undefined, {
|
||||
}, {
|
||||
[id]: this.sr,
|
||||
});
|
||||
return result[0];
|
||||
|
|
@ -1763,8 +1763,6 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
filter: {
|
||||
id: this.id,
|
||||
},
|
||||
}, {
|
||||
allowMiss: true,
|
||||
}, this.sr);
|
||||
const keys = k ? [k] : Object.keys(this.children || {});
|
||||
for (const k of keys) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue