当节点在刷新时,不重复发出对missedRows的请求

This commit is contained in:
Xu Chang 2022-11-27 11:27:33 +08:00
parent 29ee116ffc
commit f4b38af1aa
6 changed files with 28 additions and 23 deletions

View File

@ -33,13 +33,13 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict, Cxt extends A
* @param selection
* @param opers
*/
tryRedoOperationsThenSelect<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, opers: Array<{
tryRedoOperationsThenSelect<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], opers: Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}>): Partial<ED[T]["Schema"]>[];
}>, allowMiss?: boolean): Partial<ED[T]["Schema"]>[];
private getInner;
get<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, params?: SelectOption): Partial<ED[T]["Schema"]>[];
judgeRelation(entity: keyof ED, attr: string): string | 0 | 1 | 2 | string[];
get<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], params?: SelectOption): Partial<ED[T]["Schema"]>[];
judgeRelation(entity: keyof ED, attr: string): string | 0 | 2 | 1 | string[];
bindOnSync(callback: (opRecords: OpRecord<ED>[]) => void): void;
unbindOnSync(callback: (opRecords: OpRecord<ED>[]) => void): void;
getCachedData(): { [T in keyof ED]?: ED[T]["OpSchema"][] | undefined; };

View File

@ -160,7 +160,7 @@ var Cache = /** @class */ (function (_super) {
* @param selection
* @param opers
*/
Cache.prototype.tryRedoOperationsThenSelect = function (entity, selection, opers) {
Cache.prototype.tryRedoOperationsThenSelect = function (entity, selection, opers, allowMiss) {
var e_2, _a;
var context = this.contextBuilder();
context.begin();
@ -184,7 +184,7 @@ var Cache = /** @class */ (function (_super) {
finally { if (e_2) throw e_2.error; }
}
(0, selection_1.reinforceSelection)(this.cacheStore.getSchema(), entity, selection);
var result = this.getInner(entity, selection, context);
var result = this.getInner(entity, selection, context, allowMiss);
context.rollback();
return result;
}
@ -193,7 +193,7 @@ var Cache = /** @class */ (function (_super) {
throw err;
}
};
Cache.prototype.getInner = function (entity, selection, context) {
Cache.prototype.getInner = function (entity, selection, context, allowMiss) {
try {
var result = this.cacheStore.select(entity, selection, context, {
dontCollect: true,
@ -202,8 +202,10 @@ var Cache = /** @class */ (function (_super) {
}
catch (err) {
if (err instanceof Exception_1.OakRowUnexistedException) {
var missedRows = err.getRows();
this.exec('fetchRows', missedRows);
if (!allowMiss) {
var missedRows = err.getRows();
this.exec('fetchRows', missedRows);
}
return [];
}
else {

View File

@ -38,7 +38,7 @@ declare abstract class Node<ED extends EntityDict & BaseEntityDict, T extends ke
setExecuting(executing: boolean): void;
getParent(): SingleNode<ED, keyof ED, Cxt, FrontCxt, AD> | ListNode<ED, T, Cxt, FrontCxt, AD> | VirtualNode<ED, Cxt, FrontCxt, AD> | undefined;
protected getProjection(): ED[T]["Selection"]["data"];
protected judgeRelation(attr: string): string | 0 | 1 | 2 | string[];
protected judgeRelation(attr: string): string | 0 | 2 | 1 | string[];
protected contains(filter: ED[T]['Selection']['filter'], conditionalFilter: ED[T]['Selection']['filter']): boolean;
protected repel(filter1: ED[T]['Selection']['filter'], filter2: ED[T]['Selection']['filter']): boolean;
}

View File

@ -795,7 +795,7 @@ var ListNode = /** @class */ (function (_super) {
filter: (0, filter_1.combineFilters)([filter, { id: { $in: createdIds } }].filter(function (ele) { return !!ele; }), true),
});
}
var result = this.cache.tryRedoOperationsThenSelect(this.entity, selection, operations);
var result = this.cache.tryRedoOperationsThenSelect(this.entity, selection, operations, this.isLoading() || this.isLoadingMore());
return result;
}
return [];
@ -1278,7 +1278,7 @@ var SingleNode = /** @class */ (function (_super) {
var result = this.cache.tryRedoOperationsThenSelect(this.entity, {
data: projection,
filter: filter,
}, operations);
}, operations, this.isLoading());
return result[0];
}
};

View File

@ -165,13 +165,14 @@ export class Cache<
* @param selection
* @param opers
*/
tryRedoOperationsThenSelect<T extends keyof ED, S extends ED[T]['Selection']>(
tryRedoOperationsThenSelect<T extends keyof ED>(
entity: T,
selection: S,
selection: ED[T]['Selection'],
opers: Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}>
}>,
allowMiss?: boolean
) {
const context = this.contextBuilder!();
context.begin();
@ -190,7 +191,7 @@ export class Cache<
);
}
reinforceSelection(this.cacheStore!.getSchema(), entity, selection);
const result = this.getInner(entity, selection, context);
const result = this.getInner(entity, selection, context, allowMiss);
context.rollback();
return result;
}
@ -200,7 +201,7 @@ export class Cache<
}
}
private getInner<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, context: SyncContext<ED>): Partial<ED[T]['Schema']>[] {
private getInner<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: SyncContext<ED>, allowMiss?: boolean): Partial<ED[T]['Schema']>[] {
try {
const result = this.cacheStore!.select(
entity,
@ -213,8 +214,10 @@ export class Cache<
return result;
} catch (err) {
if (err instanceof OakRowUnexistedException) {
const missedRows = err.getRows();
this.exec('fetchRows', missedRows);
if (!allowMiss) {
const missedRows = err.getRows();
this.exec('fetchRows', missedRows);
}
return [];
} else {
throw err;
@ -222,9 +225,9 @@ export class Cache<
}
}
get<T extends keyof ED, S extends ED[T]['Selection']>(
get<T extends keyof ED>(
entity: T,
selection: S,
selection: ED[T]['Selection'],
params?: SelectOption
) {
const context = this.contextBuilder!();

View File

@ -858,7 +858,7 @@ class ListNode<
});
}
const result = this.cache.tryRedoOperationsThenSelect(this.entity, selection, operations);
const result = this.cache.tryRedoOperationsThenSelect(this.entity, selection, operations, this.isLoading() || this.isLoadingMore());
return result;
}
return [];
@ -1293,7 +1293,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
const result = this.cache.tryRedoOperationsThenSelect(this.entity, {
data: projection,
filter,
}, operations);
}, operations, this.isLoading());
return result[0];
}
}