-
-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1824 from dexie/issue1823
Repro and fix #1823
- Loading branch information
Showing
3 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/live-query/cache/adjust-optimistic-request-from-failures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { delArrayItem, isArray } from '../../functions/utils'; | ||
import { TblQueryCache } from '../../public/types/cache'; | ||
import { | ||
DBCoreMutateRequest, | ||
DBCoreMutateResponse, | ||
} from '../../public/types/dbcore'; | ||
|
||
export function adjustOptimisticFromFailures( | ||
tblCache: TblQueryCache, | ||
req: DBCoreMutateRequest, | ||
res: DBCoreMutateResponse | ||
): DBCoreMutateRequest { | ||
if (res.numFailures === 0) return req; | ||
if (req.type === 'deleteRange') { | ||
// numFailures > 0 means the deleteRange operation failed in its whole. | ||
return null; | ||
} | ||
|
||
const numBulkOps = req.keys | ||
? req.keys.length | ||
: 'values' in req && req.values | ||
? req.values.length | ||
: 1; | ||
if (res.numFailures === numBulkOps) { | ||
// Same number of failures as the number of ops. This means that all ops failed. | ||
return null; | ||
} | ||
|
||
const clone: DBCoreMutateRequest = { ...req }; | ||
|
||
if (isArray(clone.keys)) { | ||
clone.keys = clone.keys.filter((_, i) => !(i in res.failures)); | ||
} | ||
if ('values' in clone && isArray(clone.values)) { | ||
clone.values = clone.values.filter((_, i) => !(i in res.failures)); | ||
} | ||
return clone; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters