mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
on config save update meta.config on all workers
also dont make 20 socket.emit calls for each setting field, everything will be send in 1 socket call.
This commit is contained in:
@@ -76,7 +76,8 @@ Loader.init = function() {
|
||||
break;
|
||||
case 'user:connect':
|
||||
case 'user:disconnect':
|
||||
notifyWorkers(worker, message);
|
||||
case 'config:update':
|
||||
notifyWorkers(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +88,7 @@ Loader.init = function() {
|
||||
console.log('[cluster] Child Process (' + worker.process.pid + ') listening for connections.');
|
||||
});
|
||||
|
||||
function notifyWorkers(currentWorker, msg) {
|
||||
function notifyWorkers(msg) {
|
||||
Object.keys(cluster.workers).forEach(function(id) {
|
||||
cluster.workers[id].send(msg);
|
||||
});
|
||||
|
||||
@@ -61,21 +61,9 @@ define('forum/admin/settings', ['uploader', 'sounds'], function(uploader, sounds
|
||||
|
||||
saveBtn.off('click').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var done = 0,
|
||||
error;
|
||||
|
||||
for (x = 0; x < numFields; x++) {
|
||||
saveField(fields[x], onFieldSaved);
|
||||
}
|
||||
|
||||
function onFieldSaved(err) {
|
||||
if (!error && err) {
|
||||
error = err;
|
||||
}
|
||||
|
||||
done++;
|
||||
if (done === numFields) {
|
||||
if (error) {
|
||||
saveFields(fields, function onFieldsSaved(err) {
|
||||
if (err) {
|
||||
return app.alert({
|
||||
alert_id: 'config_status',
|
||||
timeout: 2500,
|
||||
@@ -91,8 +79,7 @@ define('forum/admin/settings', ['uploader', 'sounds'], function(uploader, sounds
|
||||
message: 'Your changes to the NodeBB configuration have been saved.',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
handleUploads();
|
||||
@@ -131,8 +118,11 @@ define('forum/admin/settings', ['uploader', 'sounds'], function(uploader, sounds
|
||||
socket.emit('admin.config.remove', key);
|
||||
};
|
||||
|
||||
function saveField(field, callback) {
|
||||
field = $(field);
|
||||
function saveFields(fields, callback) {
|
||||
var data = {};
|
||||
|
||||
fields.each(function() {
|
||||
var field = $(this);
|
||||
var key = field.attr('data-field'),
|
||||
value, inputType;
|
||||
|
||||
@@ -155,14 +145,23 @@ define('forum/admin/settings', ['uploader', 'sounds'], function(uploader, sounds
|
||||
value = field.val();
|
||||
}
|
||||
|
||||
socket.emit('admin.config.set', {
|
||||
key: key,
|
||||
value: value
|
||||
}, function(err) {
|
||||
if(!err && app.config[key] !== undefined) {
|
||||
app.config[key] = value;
|
||||
data[key] = value;
|
||||
});
|
||||
|
||||
socket.emit('admin.config.setMultiple', data, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(err);
|
||||
|
||||
if (app.config) {
|
||||
for(var field in data) {
|
||||
if (data.hasOwnProperty(field)) {
|
||||
app.config[field] = data[field];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -43,15 +43,54 @@ module.exports = function(Meta) {
|
||||
return callback(new Error('invalid config field'));
|
||||
}
|
||||
|
||||
db.setObjectField('config', field, value, function(err, res) {
|
||||
if (!err && Meta.config) {
|
||||
Meta.config[field] = value;
|
||||
db.setObjectField('config', field, value, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var data = {};
|
||||
data[field] = value;
|
||||
updateConfig(data);
|
||||
|
||||
callback(err, res);
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
Meta.configs.setMultiple = function(data, callback) {
|
||||
db.setObject('config', data, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
updateConfig(data);
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
function updateConfig(data) {
|
||||
var msg = {action: 'config:update', data: data};
|
||||
if (process.send) {
|
||||
process.send(msg);
|
||||
} else {
|
||||
onMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
process.on('message', onMessage);
|
||||
|
||||
function onMessage(msg) {
|
||||
if (typeof msg !== 'object') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.action === 'config:update' && Meta.config) {
|
||||
for(var field in msg.data) {
|
||||
if(msg.data.hasOwnProperty(field)) {
|
||||
Meta.config[field] = msg.data[field];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Meta.configs.setOnEmpty = function (field, value, callback) {
|
||||
Meta.configs.get(field, function (err, curValue) {
|
||||
if (err) {
|
||||
|
||||
@@ -74,7 +74,7 @@ SocketAdmin.themes.set = function(socket, data, callback) {
|
||||
callback();
|
||||
});
|
||||
};
|
||||
if (data.type == 'bootswatch') {
|
||||
if (data.type === 'bootswatch') {
|
||||
wrappedCallback();
|
||||
} else {
|
||||
widgets.reset(wrappedCallback);
|
||||
@@ -126,6 +126,31 @@ SocketAdmin.config.set = function(socket, data, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
SocketAdmin.config.setMultiple = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
meta.configs.setMultiple(data, function(err) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback();
|
||||
var setting;
|
||||
for(var field in data) {
|
||||
if (data.hasOwnProperty(field)) {
|
||||
setting = {
|
||||
key: field,
|
||||
value: data[field]
|
||||
};
|
||||
plugins.fireHook('action:config.set', setting);
|
||||
logger.monitorConfig({io: index.server}, setting);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
SocketAdmin.config.remove = function(socket, key) {
|
||||
meta.configs.remove(key);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user