Skip to content

Commit

Permalink
always use slice() for applying offset and limit in loki storage inst…
Browse files Browse the repository at this point in the history
…ance, fixing the fuzzing test run
  • Loading branch information
Connum committed Mar 12, 2024
1 parent 547bc45 commit cca6c1f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 3 additions & 18 deletions src/plugins/storage-lokijs/rx-storage-instance-loki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,6 @@ export class RxStorageInstanceLoki<RxDocType> 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));


Expand All @@ -280,10 +266,9 @@ export class RxStorageInstanceLoki<RxDocType> 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
Expand Down

0 comments on commit cca6c1f

Please sign in to comment.