Skip to content

Commit 315aad3

Browse files
committed
Use options object instead of boolean
1 parent c362db6 commit 315aad3

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

src/Controllers/DatabaseController.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ DatabaseController.prototype.validateClassName = function(className) {
109109
};
110110

111111
// Returns a promise for a schemaController.
112-
DatabaseController.prototype.loadSchema = function(force = false) {
112+
DatabaseController.prototype.loadSchema = function(options = {clearCache: false}) {
113113
if (!this.schemaPromise) {
114-
this.schemaPromise = SchemaController.load(this.adapter, this.schemaCache, force);
114+
this.schemaPromise = SchemaController.load(this.adapter, this.schemaCache, options);
115115
this.schemaPromise.then(() => delete this.schemaPromise);
116116
}
117117
return this.schemaPromise;

src/Controllers/SchemaController.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ class SchemaController {
282282
this.perms = {};
283283
}
284284

285-
reloadData(clearCache = false) {
285+
reloadData(options = {clearCache: false}) {
286286
this.data = {};
287287
this.perms = {};
288-
if (clearCache) {
288+
if (options.clearCache) {
289289
this._cache.clear();
290290
}
291-
return this.getAllClasses(clearCache)
291+
return this.getAllClasses(options)
292292
.then(allSchemas => {
293293
allSchemas.forEach(schema => {
294294
this.data[schema.className] = injectDefaultSchema(schema).fields;
@@ -306,12 +306,12 @@ class SchemaController {
306306
});
307307
}
308308

309-
getAllClasses(clearCache = false) {
310-
if (clearCache) {
309+
getAllClasses(options = {clearCache: false}) {
310+
if (options.clearCache) {
311311
this._cache.clear();
312312
}
313313
return this._cache.getAllClasses().then((allClasses) => {
314-
if (allClasses && allClasses.length && !clearCache) {
314+
if (allClasses && allClasses.length && !options.clearCache) {
315315
return Promise.resolve(allClasses);
316316
}
317317
return this._dbAdapter.getAllClasses()
@@ -323,17 +323,17 @@ class SchemaController {
323323
});
324324
}
325325

326-
getOneSchema(className, allowVolatileClasses = false, clearCache) {
327-
if (clearCache) {
326+
getOneSchema(className, allowVolatileClasses = false, options = {clearCache: false}) {
327+
if (options.clearCache) {
328328
this._cache.clear();
329329
}
330+
if (allowVolatileClasses && volatileClasses.indexOf(className) > -1) {
331+
return Promise.resolve(this.data[className]);
332+
}
330333
return this._cache.getOneSchema(className).then((cached) => {
331-
if (cached && !clearCache) {
334+
if (cached && !options.clearCache) {
332335
return Promise.resolve(cached);
333336
}
334-
if (allowVolatileClasses && volatileClasses.indexOf(className) > -1) {
335-
return Promise.resolve(this.data[className]);
336-
}
337337
return this._dbAdapter.getClass(className)
338338
.then(injectDefaultSchema)
339339
.then((result) => {
@@ -407,7 +407,7 @@ class SchemaController {
407407
});
408408

409409
return Promise.all(deletePromises) // Delete Everything
410-
.then(() => this.reloadData(true)) // Reload our Schema, so we have all the new values
410+
.then(() => this.reloadData({ clearCache: true })) // Reload our Schema, so we have all the new values
411411
.then(() => {
412412
let promises = insertedFields.map(fieldName => {
413413
const type = submittedFields[fieldName];
@@ -441,13 +441,13 @@ class SchemaController {
441441
// We don't have this class. Update the schema
442442
return this.addClassIfNotExists(className)
443443
// The schema update succeeded. Reload the schema
444-
.then(() => this.reloadData(true))
444+
.then(() => this.reloadData({ clearCache: true }))
445445
.catch(error => {
446446
// The schema update failed. This can be okay - it might
447447
// have failed because there's a race condition and a different
448448
// client is making the exact same schema update that we want.
449449
// So just reload the schema.
450-
return this.reloadData(true);
450+
return this.reloadData({ clearCache: true });
451451
})
452452
.then(() => {
453453
// Ensure that the schema now validates
@@ -517,7 +517,7 @@ class SchemaController {
517517
}
518518
validateCLP(perms, newSchema);
519519
return this._dbAdapter.setClassLevelPermissions(className, perms)
520-
.then(() => this.reloadData(true));
520+
.then(() => this.reloadData({ clearCache: true }));
521521
}
522522

523523
// Returns a promise that resolves successfully to the new schema
@@ -557,14 +557,14 @@ class SchemaController {
557557

558558
return this._dbAdapter.addFieldIfNotExists(className, fieldName, type).then(() => {
559559
// The update succeeded. Reload the schema
560-
return this.reloadData(true);
560+
return this.reloadData({ clearCache: true });
561561
}, error => {
562562
//TODO: introspect the error and only reload if the error is one for which is makes sense to reload
563563

564564
// The update failed. This can be okay - it might have been a race
565565
// condition where another client updated the schema in the same
566566
// way that we wanted to. So, just reload the schema
567-
return this.reloadData(true);
567+
return this.reloadData({ clearCache: true });
568568
}).then(error => {
569569
// Ensure that the schema now validates
570570
if (!dbTypeMatchesObjectType(this.getExpectedType(className, fieldName), type)) {
@@ -596,7 +596,7 @@ class SchemaController {
596596
throw new Parse.Error(136, `field ${fieldName} cannot be changed`);
597597
}
598598

599-
return this.getOneSchema(className, false, true)
599+
return this.getOneSchema(className, false, {clearCache: true})
600600
.catch(error => {
601601
if (error === undefined) {
602602
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`);
@@ -746,9 +746,9 @@ class SchemaController {
746746
}
747747

748748
// Returns a promise for a new Schema.
749-
const load = (dbAdapter, schemaCache, clearCache) => {
749+
const load = (dbAdapter, schemaCache, options) => {
750750
let schema = new SchemaController(dbAdapter, schemaCache);
751-
return schema.reloadData(clearCache).then(() => schema);
751+
return schema.reloadData(options).then(() => schema);
752752
}
753753

754754
// Builds a new schema (in schema API response format) out of an

src/ParseServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class ParseServer {
136136
expireInactiveSessions = true,
137137
verbose = false,
138138
revokeSessionOnPasswordReset = true,
139-
schemaCacheTTL = 0, // 0 = no cache
139+
schemaCacheTTL = 3600, // 0 = no cache
140140
__indexBuildCompletionCallbackForTests = () => {},
141141
}) {
142142
// Initialize the node client SDK automatically

src/Routers/SchemasRouter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ function classNameMismatchResponse(bodyClass, pathClass) {
1515
}
1616

1717
function getAllSchemas(req) {
18-
return req.config.database.loadSchema(true)
18+
return req.config.database.loadSchema({ clearCache: true})
1919
.then(schemaController => schemaController.getAllClasses(true))
2020
.then(schemas => ({ response: { results: schemas } }));
2121
}
2222

2323
function getOneSchema(req) {
2424
const className = req.params.className;
25-
return req.config.database.loadSchema(true)
25+
return req.config.database.loadSchema({ clearCache: true})
2626
.then(schemaController => schemaController.getOneSchema(className, true))
2727
.then(schema => ({ response: schema }))
2828
.catch(error => {
@@ -46,7 +46,7 @@ function createSchema(req) {
4646
throw new Parse.Error(135, `POST ${req.path} needs a class name.`);
4747
}
4848

49-
return req.config.database.loadSchema(true)
49+
return req.config.database.loadSchema({ clearCache: true})
5050
.then(schema => schema.addClassIfNotExists(className, req.body.fields, req.body.classLevelPermissions))
5151
.then(schema => ({ response: schema }));
5252
}
@@ -59,7 +59,7 @@ function modifySchema(req) {
5959
let submittedFields = req.body.fields || {};
6060
let className = req.params.className;
6161

62-
return req.config.database.loadSchema(true)
62+
return req.config.database.loadSchema({ clearCache: true})
6363
.then(schema => schema.updateClass(className, submittedFields, req.body.classLevelPermissions, req.config.database))
6464
.then(result => ({response: result}));
6565
}

0 commit comments

Comments
 (0)