Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ export function createMutationTrackingMiddleware({
txid,
userId,
};

if ('isAdditionalChunk' in req && req.isAdditionalChunk) {
mut.isAdditionalChunk = true;
}
return keys.length > 0 || ('criteria' in req && req.criteria)
? mutsTable
.mutate({ type: 'add', trans, values: [mut] }) // Log entry
Expand Down
2 changes: 1 addition & 1 deletion libs/dexie-cloud-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dexie-cloud-common",
"version": "1.0.33",
"version": "1.0.34",
"description": "Library for shared code between dexie-cloud-addon, dexie-cloud (CLI) and dexie-cloud-server",
"type": "module",
"module": "dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions libs/dexie-cloud-common/src/DBOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface DBOperationCommon<PK=DBOpPrimaryKey> {
txid?: string | null;
userId?: string | null;
opNo?: number;
isAdditionalChunk?: boolean;
}
export interface DBInsertOperation<PK=DBOpPrimaryKey> extends DBOperationCommon<PK> {
type: "insert";
Expand Down
22 changes: 12 additions & 10 deletions src/classes/collection/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Collection implements ICollection {
* https://dexie.org/docs/Collection/Collection.clone()
*
**/
clone(props?) {
clone(props?): this {
var rv = Object.create(this.constructor.prototype),
ctx = Object.create(this._ctx);
if (props) extend(ctx, props);
Expand All @@ -87,7 +87,7 @@ export class Collection implements ICollection {
* https://dexie.org/docs/Collection/Collection.raw()
*
**/
raw() {
raw(): this {
this._ctx.valueMapper = null;
return this;
}
Expand Down Expand Up @@ -503,6 +503,12 @@ export class Collection implements ICollection {
}
}
return this.clone().primaryKeys().then(keys => {
const criteria = isPlainKeyRange(ctx) &&
ctx.limit === Infinity &&
(typeof changes !== 'function' || changes === deleteCallback) && {
index: ctx.index,
range: ctx.range
};

const nextChunk = (offset: number) => {
const count = Math.min(limit, keys.length - offset);
Expand Down Expand Up @@ -539,12 +545,6 @@ export class Collection implements ICollection {
}
}
}
const criteria = isPlainKeyRange(ctx) &&
ctx.limit === Infinity &&
(typeof changes !== 'function' || changes === deleteCallback) && {
index: ctx.index,
range: ctx.range
};

return Promise.resolve(addValues.length > 0 &&
coreTable.mutate({trans, type: 'add', values: addValues})
Expand All @@ -563,14 +563,16 @@ export class Collection implements ICollection {
values: putValues,
criteria,
changeSpec: typeof changes !== 'function'
&& changes
&& changes,
isAdditionalChunk: offset > 0
}).then(res=>applyMutateResult(putValues.length, res))
).then(()=>(deleteKeys.length > 0 || (criteria && changes === deleteCallback)) &&
coreTable.mutate({
trans,
type: 'delete',
keys: deleteKeys,
criteria
criteria,
isAdditionalChunk: offset > 0
}).then(res=>applyMutateResult(deleteKeys.length, res))
).then(()=>{
return keys.length > offset + count && nextChunk(offset + limit);
Expand Down
2 changes: 2 additions & 0 deletions src/public/types/dbcore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface DBCorePutRequest {
range: DBCoreKeyRange;
};
changeSpec?: {[keyPath: string]: any}; // Common changeSpec for each key
isAdditionalChunk?: boolean;
updates?: {
keys: any[],
changeSpecs: {[keyPath: string]: any}[]; // changeSpec per key.
Expand All @@ -74,6 +75,7 @@ export interface DBCoreDeleteRequest {
index: string | null;
range: DBCoreKeyRange;
};
isAdditionalChunk?: boolean;
}

export interface DBCoreDeleteRangeRequest {
Expand Down