From f4b38af1aaccc3b7c8648c05f946d1c37edd704d Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Sun, 27 Nov 2022 11:27:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E8=8A=82=E7=82=B9=E5=9C=A8=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E6=97=B6,=E4=B8=8D=E9=87=8D=E5=A4=8D=E5=8F=91?= =?UTF-8?q?=E5=87=BA=E5=AF=B9missedRows=E7=9A=84=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/features/cache.d.ts | 8 ++++---- lib/features/cache.js | 12 +++++++----- lib/features/runningTree.d.ts | 2 +- lib/features/runningTree.js | 4 ++-- src/features/cache.ts | 21 ++++++++++++--------- src/features/runningTree.ts | 4 ++-- 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/lib/features/cache.d.ts b/lib/features/cache.d.ts index 150fce8e..c4c0caa6 100644 --- a/lib/features/cache.d.ts +++ b/lib/features/cache.d.ts @@ -33,13 +33,13 @@ export declare class Cache(entity: T, selection: S, opers: Array<{ + tryRedoOperationsThenSelect(entity: T, selection: ED[T]['Selection'], opers: Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; - }>): Partial[]; + }>, allowMiss?: boolean): Partial[]; private getInner; - get(entity: T, selection: S, params?: SelectOption): Partial[]; - judgeRelation(entity: keyof ED, attr: string): string | 0 | 1 | 2 | string[]; + get(entity: T, selection: ED[T]['Selection'], params?: SelectOption): Partial[]; + judgeRelation(entity: keyof ED, attr: string): string | 0 | 2 | 1 | string[]; bindOnSync(callback: (opRecords: OpRecord[]) => void): void; unbindOnSync(callback: (opRecords: OpRecord[]) => void): void; getCachedData(): { [T in keyof ED]?: ED[T]["OpSchema"][] | undefined; }; diff --git a/lib/features/cache.js b/lib/features/cache.js index 8f431960..6861fe04 100644 --- a/lib/features/cache.js +++ b/lib/features/cache.js @@ -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 { diff --git a/lib/features/runningTree.d.ts b/lib/features/runningTree.d.ts index 1039d78e..c9c59ac9 100644 --- a/lib/features/runningTree.d.ts +++ b/lib/features/runningTree.d.ts @@ -38,7 +38,7 @@ declare abstract class Node | ListNode | VirtualNode | 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; } diff --git a/lib/features/runningTree.js b/lib/features/runningTree.js index 17ca6fbc..bb094315 100644 --- a/lib/features/runningTree.js +++ b/lib/features/runningTree.js @@ -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]; } }; diff --git a/src/features/cache.ts b/src/features/cache.ts index c3d20790..d8bf12b3 100644 --- a/src/features/cache.ts +++ b/src/features/cache.ts @@ -165,13 +165,14 @@ export class Cache< * @param selection * @param opers */ - tryRedoOperationsThenSelect( + tryRedoOperationsThenSelect( 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(entity: T, selection: S, context: SyncContext): Partial[] { + private getInner(entity: T, selection: ED[T]['Selection'], context: SyncContext, allowMiss?: boolean): Partial[] { 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( + get( entity: T, - selection: S, + selection: ED[T]['Selection'], params?: SelectOption ) { const context = this.contextBuilder!(); diff --git a/src/features/runningTree.ts b/src/features/runningTree.ts index 0a55a7e5..b5edcd8a 100644 --- a/src/features/runningTree.ts +++ b/src/features/runningTree.ts @@ -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