From cca6c1f8ba9258ace02a05223640234feb9ee659 Mon Sep 17 00:00:00 2001 From: Connum Date: Sun, 10 Mar 2024 16:04:56 +0100 Subject: [PATCH] always use slice() for applying offset and limit in loki storage instance, fixing the fuzzing test run --- package.json | 1 + .../rx-storage-instance-loki.ts | 21 +++---------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index cda755845b3..e66b9968c1d 100644 --- a/package.json +++ b/package.json @@ -401,6 +401,7 @@ "test:performance": "npm run build && npm run test:performance:lokijs:browser && npm run test:performance:lokijs:node && npm run test:performance:dexie && npm run test:performance:memory:browser && npm run test:performance:memory:node", "test:query-correctness-fuzzing:memory:node": "npm run transpile && cross-env DEFAULT_STORAGE=memory mocha --config ./config/.mocharc.cjs ./test_tmp/query-correctness-fuzzing.test.js --unhandled-rejections=strict --expose-gc", "test:query-correctness-fuzzing:custom:node": "npm run transpile && cross-env DEFAULT_STORAGE=custom mocha --config ./config/.mocharc.cjs ./test_tmp/query-correctness-fuzzing.test.js --unhandled-rejections=strict --expose-gc", + "test:query-correctness-fuzzing:lokijs:node": "npm run transpile && cross-env DEFAULT_STORAGE=lokijs mocha --config ./config/.mocharc.cjs ./test_tmp/query-correctness-fuzzing.test.js --unhandled-rejections=strict --expose-gc", "couch:start": "docker run -p 5984:5984 -e COUCHDB_USER=root -e COUCHDB_PASSWORD=root --rm --name rxdb-couchdb couchdb:3.3.1", "couch:stop": "docker rm -f rxdb-couchdb", "mongodb:start": "docker run -p 27017:27017 -p 27018:27018 -p 27019:27019 --rm --name rxdb-mongodb mongo:7.0.1", diff --git a/src/plugins/storage-lokijs/rx-storage-instance-loki.ts b/src/plugins/storage-lokijs/rx-storage-instance-loki.ts index 99ada5be234..8b65388d4f9 100644 --- a/src/plugins/storage-lokijs/rx-storage-instance-loki.ts +++ b/src/plugins/storage-lokijs/rx-storage-instance-loki.ts @@ -251,20 +251,6 @@ export class RxStorageInstanceLoki implements RxStorageInstance< } - - - /** - * Offset must be used before limit in LokiJS - * @link https://github.com/techfort/LokiJS/issues/570 - */ - if (!mustRunMatcher && preparedQuery.skip) { - lokiQuery = lokiQuery.offset(preparedQuery.skip); - } - - if (!mustRunMatcher && preparedQuery.limit) { - lokiQuery = lokiQuery.limit(preparedQuery.limit); - } - let foundDocuments = lokiQuery.data().map((lokiDoc: any) => stripLokiKey(lokiDoc)); @@ -280,10 +266,9 @@ export class RxStorageInstanceLoki implements RxStorageInstance< ); foundDocuments = foundDocuments.filter((d: any) => queryMatcher(d)); - - if (mustRunMatcher) { - foundDocuments = foundDocuments.slice(skip, skipPlusLimit); - } + // always apply offset and limit like this, because + // sylvieQuery.offset() and sylvieQuery.limit() results were inconsistent + foundDocuments = foundDocuments.slice(skip, skipPlusLimit); return { documents: foundDocuments