Make parts of SchemasRouter use adaptiveCollection.

This commit is contained in:
Nikita Lutsenko
2016-03-01 20:24:36 -08:00
parent abde9484ce
commit 9538a7dab5
2 changed files with 22 additions and 19 deletions

View File

@@ -46,4 +46,8 @@ export default class MongoCollection {
count(query, { skip, limit, sort } = {}) { count(query, { skip, limit, sort } = {}) {
return this._mongoCollection.count(query, { skip, limit, sort }); return this._mongoCollection.count(query, { skip, limit, sort });
} }
drop() {
return this._mongoCollection.drop();
}
} }

View File

@@ -38,11 +38,10 @@ function mongoSchemaToSchemaAPIResponse(schema) {
} }
function getAllSchemas(req) { function getAllSchemas(req) {
return req.config.database.collection('_SCHEMA') return req.config.database.adaptiveCollection('_SCHEMA')
.then(coll => coll.find({}).toArray()) .then(collection => collection.find({}))
.then(schemas => ({response: { .then(schemas => schemas.map(mongoSchemaToSchemaAPIResponse))
results: schemas.map(mongoSchemaToSchemaAPIResponse) .then(schemas => ({ response: { results: schemas }}));
}}));
} }
function getOneSchema(req) { function getOneSchema(req) {
@@ -152,7 +151,7 @@ function deleteSchema(req) {
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, Schema.invalidClassNameMessage(req.params.className)); throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, Schema.invalidClassNameMessage(req.params.className));
} }
return req.config.database.collection(req.params.className) return req.config.database.adaptiveCollection(req.params.className)
.then(collection => { .then(collection => {
return collection.count() return collection.count()
.then(count => { .then(count => {
@@ -161,19 +160,19 @@ function deleteSchema(req) {
} }
return collection.drop(); return collection.drop();
}) })
.then(() => { })
// We've dropped the collection now, so delete the item from _SCHEMA .then(() => {
// and clear the _Join collections // We've dropped the collection now, so delete the item from _SCHEMA
return req.config.database.collection('_SCHEMA') // and clear the _Join collections
.then(coll => coll.findAndRemove({_id: req.params.className}, [])) return req.config.database.collection('_SCHEMA')
.then(doc => { .then(coll => coll.findAndRemove({_id: req.params.className}, []))
if (doc.value === null) { .then(doc => {
//tried to delete non-existent class if (doc.value === null) {
return Promise.resolve(); //tried to delete non-existent class
} return Promise.resolve();
return removeJoinTables(req.config.database, doc.value); }
}); return removeJoinTables(req.config.database, doc.value);
}) });
}) })
.then(() => { .then(() => {
// Success // Success