Skip to content
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

Performance improvements #2371

Merged
Merged
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
1 change: 0 additions & 1 deletion frontend/src/modules/scaffold/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ define([ 'core/origin', './models/schemasModel' ], function(Origin, SchemasModel
function trimGlobals(schema) {
var globals = schema._globals.properties;
trimDisabledPlugins(globals._extensions, _.values(configModel.get('_enabledExtensions')));
trimDisabledPlugins(globals._components, configModel.get('_enabledComponents'), '_component');
trimDisabledPlugins(globals._menu, editorData.menutypes.where({ name: configModel.get('_menu') }));
trimDisabledPlugins(globals._theme, editorData.themetypes.where({ name: configModel.get('_theme') }));
// trim off the empty globals objects
Expand Down
40 changes: 32 additions & 8 deletions lib/outputmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,32 @@ function getConfigJson(courseId, callback) {
if (config.length !== 1) {
return callback(new Error('Preview/Publish: Unable to retrieve config.json'));
}
callback(null, { config: [flattenNestedObjects(config[0])] });

// Retrieve the component types.
database.getDatabase(function(err, db) {
if (err) {
logger.log('error', err);
return next(err);
}

db.retrieve('component', {_courseId: courseId}, {operators: {distinct: '_component'}}, function (err, components) {
db.retrieve('componenttype', {}, function(err, componentTypes) {
if (err) {
return next(err);
}

async.map(components, function(component, callback) {
var componentType = _.findWhere(componentTypes, {component: component});
return callback(null, { name: componentType.name });
}, function(err, uniqueComponentList) {
var configModel = config[0].toObject();
configModel._enabledComponents = uniqueComponentList;

callback(null, { config: [flattenNestedObjects(configModel)] });
});
});
});
}, configuration.getConfig('dbName'));
});
});
}
Expand Down Expand Up @@ -276,13 +301,10 @@ OutputPlugin.prototype.sanitizeCourseJSON = function(mode, json, next) {
OutputPlugin.prototype.generateIncludesForCourse = function(courseId, next) {
async.waterfall([
(callback) => {
origin().contentmanager.getContentPlugin('config', callback);
getConfigJson(courseId, callback);
},
(contentPlugin, callback) => {
contentPlugin.retrieve({ _courseId: courseId }, {}, callback);
},
(config, callback) => {
this.generateIncludesForConfig(config[0], (error, includes) => {
(json, callback) => {
this.generateIncludesForConfig(json.config[0], (error, includes) => {
if(error) {
return callback(error);
}
Expand Down Expand Up @@ -338,7 +360,9 @@ function generateIncludedPlugins(config) {
// string, store and return
if(typeof val === 'string') return includedPlugins.push([ pluginTypeInfo.folder, val ]);
// either object or array, store each 'name' value
for(var i in val) includedPlugins.push([ pluginTypeInfo.folder, val[i].name ]);
for(var i in val) {
if (typeof val[i].name !== 'undefined') includedPlugins.push([ pluginTypeInfo.folder, val[i].name ]);
}
});
return includedPlugins;
}
Expand Down
51 changes: 2 additions & 49 deletions plugins/content/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,55 +148,8 @@ ConfigContent.prototype.retrieve = function (search, options, next) {
if (!records || records.length == 0) {
return next(new Error(`Unable to retrieve ${modelName} for ${JSON.stringify(search)}`));
}

// When passing down the config model we should
// find out how many and what components are being used
// Why you might ask - to sort out _globals and when compiling
// this should act as a filter
app.contentmanager.getContentPlugin('component', function (err, componentPlugin) {
var courseId = records[0]._courseId;
componentPlugin.retrieve({_courseId: courseId}, function(err, components) {

// Retrieve the component types.
database.getDatabase(function(err, db) {
if (err) {
logger.log('error', err);
return next(err);
}

db.retrieve('componenttype', {}, function(err, componentTypes) {
if (err) {
return next(err);
}

var uniqueComponents = _.uniq(components, false, function(component) {
return component._component;
});

async.map(uniqueComponents, function(component, callback) {
var componentType = _.findWhere(componentTypes, {component: component._component});

// Adding an _ here is necessary because of the way the attributes are set
// onto the _globals object on the schemas
var definition = {
name: componentType.name,
_componentType: component._componentType,
_component: "_" + component._component
};

return callback(null, definition);

}, function(err, uniqueComponentList) {

var configModel = records[0].toObject();
configModel._enabledComponents = uniqueComponentList;

return next(null, [configModel]);
});
});
}, configuration.getConfig('dbName'));
})
});

return next(null, [records[0]]);
});
};

Expand Down
4 changes: 2 additions & 2 deletions plugins/output/adapt/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function publishCourse(courseId, mode, request, response, next) {
return stdout.substring(indexStart, indexEnd !== -1 ? indexEnd : stdout.length);
}

async.series([
async.waterfall([
// get an object with all the course data
function(callback) {
self.getCourseJSON(tenantId, courseId, function(err, data) {
Expand Down Expand Up @@ -200,7 +200,7 @@ function publishCourse(courseId, mode, request, response, next) {
});
});
},
function(callback) {
function(err, callback) {
self.clearBuildFlag(path.join(BUILD_FOLDER, Constants.Filenames.Rebuild), function(err) {
callback(null);
});
Expand Down