Skip to content

Optimisation for schemas with many fields #4567

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

Closed
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1307,4 +1307,16 @@ describe('Class Level Permissions for requiredAuth', () => {
done.fail(e);
});
});
})

it('is not possible to modify the loaded schema', (done) => {
config.database.loadSchema().then((schemaController) => {
return schemaController.getOneSchema('_User');
}).then((schema) => {
schema.fields.addedField = 'added';
}).then(() => {
done.fail('should not succeed');
}).catch(() => {
done();
});
});
});
23 changes: 12 additions & 11 deletions src/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ const injectDefaultSchema = ({className, fields, classLevelPermissions, indexes}
...(defaultColumns[className] || {}),
...fields,
},
classLevelPermissions,
classLevelPermissions
};
if (indexes && Object.keys(indexes).length !== 0) {
defaultSchema.indexes = indexes;
Expand All @@ -330,26 +330,26 @@ const injectDefaultSchema = ({className, fields, classLevelPermissions, indexes}

const _HooksSchema = {className: "_Hooks", fields: defaultColumns._Hooks};
const _GlobalConfigSchema = { className: "_GlobalConfig", fields: defaultColumns._GlobalConfig }
const _PushStatusSchema = convertSchemaToAdapterSchema(injectDefaultSchema({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to call injectDefaultSchema here as it is called inside convertSchemaToAdapterSchema

const _PushStatusSchema = convertSchemaToAdapterSchema({
className: "_PushStatus",
fields: {},
classLevelPermissions: {}
}));
const _JobStatusSchema = convertSchemaToAdapterSchema(injectDefaultSchema({
});
const _JobStatusSchema = convertSchemaToAdapterSchema({
className: "_JobStatus",
fields: {},
classLevelPermissions: {}
}));
const _JobScheduleSchema = convertSchemaToAdapterSchema(injectDefaultSchema({
});
const _JobScheduleSchema = convertSchemaToAdapterSchema({
className: "_JobSchedule",
fields: {},
classLevelPermissions: {}
}));
const _AudienceSchema = convertSchemaToAdapterSchema(injectDefaultSchema({
});
const _AudienceSchema = convertSchemaToAdapterSchema({
className: "_Audience",
fields: defaultColumns._Audience,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent and not required as convertSchemaToAdapterSchema calls injectDefaultSchema which adds these fields anyway

fields: {},
classLevelPermissions: {}
}));
});
const VolatileClassesSchemas = [_HooksSchema, _JobStatusSchema, _JobScheduleSchema, _PushStatusSchema, _GlobalConfigSchema, _AudienceSchema];

const dbTypeMatchesObjectType = (dbType: SchemaField | string, objectType: SchemaField) => {
Expand Down Expand Up @@ -407,7 +407,8 @@ export default class SchemaController {
const perms = {};
const indexes = {};
allSchemas.forEach(schema => {
data[schema.className] = injectDefaultSchema(schema).fields;
Object.freeze(schema.fields);
data[schema.className] = schema.fields;
perms[schema.className] = schema.classLevelPermissions;
indexes[schema.className] = schema.indexes;
});
Expand Down