Remove acceptor parameter (#1553)

This commit is contained in:
Drew
2016-04-19 14:29:05 -07:00
parent 3945e0c680
commit bf47a0b2b6

View File

@@ -58,26 +58,15 @@ DatabaseController.prototype.validateClassName = function(className) {
// Returns a promise for a schema object. // Returns a promise for a schema object.
// If we are provided a acceptor, then we run it on the schema. // If we are provided a acceptor, then we run it on the schema.
// If the schema isn't accepted, we reload it at most once. // If the schema isn't accepted, we reload it at most once.
DatabaseController.prototype.loadSchema = function(acceptor = () => true) { DatabaseController.prototype.loadSchema = function() {
if (!this.schemaPromise) { if (!this.schemaPromise) {
this.schemaPromise = this.schemaCollection().then(collection => { this.schemaPromise = this.schemaCollection().then(collection => {
delete this.schemaPromise; delete this.schemaPromise;
return SchemaController.load(collection, this.adapter); return SchemaController.load(collection, this.adapter);
}); });
return this.schemaPromise;
} }
return this.schemaPromise;
return this.schemaPromise.then((schema) => {
if (acceptor(schema)) {
return schema;
}
this.schemaPromise = this.schemaCollection().then(collection => {
delete this.schemaPromise;
return SchemaController.load(collection, this.adapter);
});
return this.schemaPromise;
});
}; };
// Returns a promise for the classname that is related to the given // Returns a promise for the classname that is related to the given
@@ -147,13 +136,10 @@ DatabaseController.prototype.update = function(className, query, update, options
// Make a copy of the object, so we don't mutate the incoming data. // Make a copy of the object, so we don't mutate the incoming data.
update = deepcopy(update); update = deepcopy(update);
var acceptor = function(schema) {
return schema.hasKeys(className, Object.keys(query));
};
var isMaster = !('acl' in options); var isMaster = !('acl' in options);
var aclGroup = options.acl || []; var aclGroup = options.acl || [];
var mongoUpdate, schema; var mongoUpdate, schema;
return this.loadSchema(acceptor) return this.loadSchema()
.then(s => { .then(s => {
schema = s; schema = s;
if (!isMaster) { if (!isMaster) {
@@ -586,9 +572,8 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
} }
let isMaster = !('acl' in options); let isMaster = !('acl' in options);
let aclGroup = options.acl || []; let aclGroup = options.acl || [];
let acceptor = schema => schema.hasKeys(className, keysForQuery(query))
let schema = null; let schema = null;
return this.loadSchema(acceptor).then(s => { return this.loadSchema().then(s => {
schema = s; schema = s;
if (options.sort) { if (options.sort) {
mongoOptions.sort = {}; mongoOptions.sort = {};