Fix "loaded" hook for unoptimized "near" queries
Before this change, two "loaded" events were emitted for every model
instance found. This commit fixes the problem and restores the intended
behavior.
The bug was probably introduced by 5e0c73bec7
.
This commit is contained in:
parent
caf9d09274
commit
344441d48d
26
lib/dao.js
26
lib/dao.js
|
@ -1569,7 +1569,8 @@ DataAccessObject.find = function find(query, options, cb) {
|
|||
return cb.promise;
|
||||
}
|
||||
}
|
||||
function geoCallbackWithoutNotify(err, data) {
|
||||
|
||||
function geoCallback(err, data) {
|
||||
const memory = new Memory();
|
||||
const modelName = self.modelName;
|
||||
|
||||
|
@ -1588,37 +1589,14 @@ DataAccessObject.find = function find(query, options, cb) {
|
|||
});
|
||||
});
|
||||
|
||||
// FIXME: apply "includes" and other transforms - see allCb below
|
||||
memory.all(modelName, geoQueryObject, options, allCb);
|
||||
} else {
|
||||
cb(null, []);
|
||||
}
|
||||
}
|
||||
|
||||
function geoCallbackWithNotify(err, data) {
|
||||
if (err) return cb(err);
|
||||
|
||||
async.map(data, function(item, next) {
|
||||
const context = {
|
||||
Model: self,
|
||||
data: item,
|
||||
isNewInstance: false,
|
||||
hookState: hookState,
|
||||
options: options,
|
||||
};
|
||||
|
||||
self.notifyObserversOf('loaded', context, function(err) {
|
||||
if (err) return next(err);
|
||||
next(null, context.data);
|
||||
});
|
||||
}, function(err, results) {
|
||||
if (err) return cb(err);
|
||||
geoCallbackWithoutNotify(null, results);
|
||||
});
|
||||
}
|
||||
function queryGeo(query) {
|
||||
geoQueryObject = query;
|
||||
const geoCallback = options.notify === false ? geoCallbackWithoutNotify : geoCallbackWithNotify;
|
||||
invokeConnectorMethod(connector, 'all', self, [{}], options, geoCallback);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue