mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Combine sorter spec with projection
This commit is contained in:
@@ -28,7 +28,8 @@ Package.on_use(function (api) {
|
||||
// Functionality used only by oplog tailing on the server side
|
||||
api.add_files([
|
||||
'selector_projection.js',
|
||||
'selector_modifier.js'
|
||||
'selector_modifier.js',
|
||||
'sorter_projection.js'
|
||||
], 'server');
|
||||
});
|
||||
|
||||
|
||||
@@ -12,12 +12,23 @@ Minimongo.Matcher.prototype.combineIntoProjection = function (projection) {
|
||||
if (_.contains(selectorPaths, ''))
|
||||
return {};
|
||||
|
||||
return combineImportantPathsIntoProjection(selectorPaths, projection);
|
||||
};
|
||||
|
||||
Minimongo.Matcher.prototype._getPathsElidingNumericKeys = function () {
|
||||
var self = this;
|
||||
return _.map(self._getPaths(), function (path) {
|
||||
return _.reject(path.split('.'), isNumericKey).join('.');
|
||||
});
|
||||
};
|
||||
|
||||
combineImportantPathsIntoProjection = function (paths, projection) {
|
||||
var prjDetails = projectionDetails(projection);
|
||||
var tree = prjDetails.tree;
|
||||
var mergedProjection = {};
|
||||
|
||||
// merge the paths to include
|
||||
tree = pathsToTree(selectorPaths,
|
||||
tree = pathsToTree(paths,
|
||||
function (path) { return true; },
|
||||
function (node, path, fullPath) { return true; },
|
||||
tree);
|
||||
@@ -40,13 +51,6 @@ Minimongo.Matcher.prototype.combineIntoProjection = function (projection) {
|
||||
}
|
||||
};
|
||||
|
||||
Minimongo.Matcher.prototype._getPathsElidingNumericKeys = function () {
|
||||
var self = this;
|
||||
return _.map(self._getPaths(), function (path) {
|
||||
return _.reject(path.split('.'), isNumericKey).join('.');
|
||||
});
|
||||
};
|
||||
|
||||
// Returns a set of key paths similar to
|
||||
// { 'foo.bar': 1, 'a.b.c': 1 }
|
||||
var treeToPaths = function (tree, prefix) {
|
||||
|
||||
@@ -38,7 +38,7 @@ Sorter = function (spec) {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw Error("Bad sort specification: ", JSON.stringify(spec));
|
||||
throw Error("Bad sort specification: " + JSON.stringify(spec));
|
||||
}
|
||||
|
||||
// reduceValue takes in all the possible values for the sort key along various
|
||||
|
||||
19
packages/minimongo/sorter_projection.js
Normal file
19
packages/minimongo/sorter_projection.js
Normal file
@@ -0,0 +1,19 @@
|
||||
Sorter.combineSpecIntoProjection = function (spec, projection) {
|
||||
var self = this;
|
||||
var specPaths = getSortSpecPaths(spec);
|
||||
|
||||
return combineImportantPathsIntoProjection(specPaths, projection);
|
||||
};
|
||||
|
||||
var getSortSpecPaths = function (spec) {
|
||||
if (_.isArray(spec))
|
||||
return _.map(spec, function (fieldSpec) {
|
||||
return _.isArray(fieldSpec) ? fieldSpec[0] : fieldSpec;
|
||||
});
|
||||
|
||||
if (_.isObject(spec))
|
||||
return _.keys(spec);
|
||||
|
||||
throw new Error("Bad sort specification: " + JSON.stringify(spec));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user