From 7f35e0ff2c9cfe7d5ca806bafa53c8a3a06566c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 13 May 2019 09:10:22 +0200 Subject: [PATCH 1/2] Test "near" queries executed in memory Rework setup of the Operation Hooks test suite for memory connector so that the "unoptimized" variant disables not only atomic CRUD operations, but also geo queries. This way we can test both "near" querying implementations: - When the connectors supports "near" queries natively. - When "near" queries are executed at LoopBack side in-memory. --- test/memory.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/memory.test.js b/test/memory.test.js index 16dccc21..80b1bc44 100644 --- a/test/memory.test.js +++ b/test/memory.test.js @@ -917,6 +917,9 @@ describe('Unoptimized connector', function() { ds.connector.findOrCreate = false; ds.connector.upsertWithWhere = false; + // disable native location queries + ds.connector.buildNearFilter = false; + require('./persistence-hooks.suite')(ds, should, { replaceOrCreateReportsNewInstance: true, }); From c4ff74a723ceb637d3dabc60b5a10dacd0d33c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 13 May 2019 09:36:46 +0200 Subject: [PATCH 2/2] Fix "access" hook for unoptimized "near" queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, when an "access" hook modified the "query" object, the "near" condition from the original "query" object were still applied. As a result, the query can end up being more restrictive and return only a subset of models that should have matched the conditions. With this change in place, after "access" hook observers are invoked, we update the "near" condition using the "query" object provided by hook observers. Signed-off-by: Miroslav Bajtoš --- lib/dao.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/dao.js b/lib/dao.js index 75bb0b09..d39e3504 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -1536,7 +1536,7 @@ DataAccessObject.find = function find(query, options, cb) { this.applyScope(query); - const near = query && geo.nearFilter(query.where); + let near = query && geo.nearFilter(query.where); const supportsGeo = !!connector.buildNearFilter; if (near) { @@ -1567,6 +1567,8 @@ DataAccessObject.find = function find(query, options, cb) { } function queryGeo(query) { + near = query && geo.nearFilter(query.where); + function geoCallbackWithoutNotify(err, data) { const memory = new Memory(); const modelName = self.modelName;