Skip to content

Remove acceptor parameter #1553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,15 @@ DatabaseController.prototype.validateClassName = function(className) {
// Returns a promise for a schema object.
// 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.
DatabaseController.prototype.loadSchema = function(acceptor = () => true) {
DatabaseController.prototype.loadSchema = function() {

if (!this.schemaPromise) {
this.schemaPromise = this.schemaCollection().then(collection => {
delete this.schemaPromise;
return SchemaController.load(collection, this.adapter);
});
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;
});
return this.schemaPromise;
};

// Returns a promise for the classname that is related to the given
Expand Down Expand Up @@ -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.
update = deepcopy(update);

var acceptor = function(schema) {
return schema.hasKeys(className, Object.keys(query));
};
var isMaster = !('acl' in options);
var aclGroup = options.acl || [];
var mongoUpdate, schema;
return this.loadSchema(acceptor)
return this.loadSchema()
.then(s => {
schema = s;
if (!isMaster) {
Expand Down Expand Up @@ -586,9 +572,8 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
}
let isMaster = !('acl' in options);
let aclGroup = options.acl || [];
let acceptor = schema => schema.hasKeys(className, keysForQuery(query))
let schema = null;
return this.loadSchema(acceptor).then(s => {
return this.loadSchema().then(s => {
schema = s;
if (options.sort) {
mongoOptions.sort = {};
Expand Down