mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-24 08:19:48 +01:00
* [test/database/list] Fix test list 4 being used in two different tests * [database/postgres] PostgreSQL database driver * [database/postgres] Make transactions work based on continuation scope. * [database/postgres] Implement nested transactions * eslint --fix * Add database changes from earlier this week to the PostgreSQL driver. * Fix typo * Fix postgres.incrObjectFieldBy returning undefined instead of null when given NaN * [database/postgres] Fix sortedSetsCard returning an array of strings. * Update socket.io postgres adapter * Fix PostgreSQL erroring when multiple updates are made to the same sorted set entry in a single operation. Add a test case to catch this error. * Fix lint errors. * Only prune sessions on one instance in a cluster to avoid deadlocks. They're caught and handled by the database server, but they spam the logs. * Fix arguments.slice.
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
var EventEmitter = require('events');
|
|
var nconf = require('nconf');
|
|
|
|
var real;
|
|
|
|
function get() {
|
|
if (real) {
|
|
return real;
|
|
}
|
|
|
|
var pubsub;
|
|
|
|
if (nconf.get('isCluster') === 'false') {
|
|
pubsub = new EventEmitter();
|
|
pubsub.publish = pubsub.emit.bind(pubsub);
|
|
} else if (nconf.get('singleHostCluster')) {
|
|
pubsub = new EventEmitter();
|
|
pubsub.publish = function (event, data) {
|
|
process.send({
|
|
action: 'pubsub',
|
|
event: event,
|
|
data: data,
|
|
});
|
|
};
|
|
process.on('message', function (message) {
|
|
if (message && typeof message === 'object' && message.action === 'pubsub') {
|
|
pubsub.emit(message.event, message.data);
|
|
}
|
|
});
|
|
} else if (nconf.get('redis')) {
|
|
pubsub = require('./database/redis/pubsub');
|
|
} else if (nconf.get('mongo')) {
|
|
pubsub = require('./database/mongo/pubsub');
|
|
} else if (nconf.get('postgres')) {
|
|
pubsub = require('./database/postgres/pubsub');
|
|
}
|
|
|
|
real = pubsub;
|
|
|
|
return pubsub;
|
|
}
|
|
|
|
module.exports = {
|
|
publish: function (event, data) {
|
|
get().publish(event, data);
|
|
},
|
|
on: function (event, callback) {
|
|
get().on(event, callback);
|
|
},
|
|
removeAllListeners: function (event) {
|
|
get().removeAllListeners(event);
|
|
},
|
|
};
|