Node.js based forum software built for the modern web
possible fix for pubsub
Barış Soner Uşaklı8a6345ded7df
diff --git a/src/database/mongo.js b/src/database/mongo.jsindex 4042cf6025..be6789389b 100644--- a/src/database/mongo.js+++ b/src/database/mongo.js@@ -122,7 +122,6 @@ mongoModule.init = function (callback) {require('./mongo/sets')(db, mongoModule);require('./mongo/sorted')(db, mongoModule);require('./mongo/list')(db, mongoModule);- require('./mongo/pubsub')(db, mongoModule);callback();});};diff --git a/src/database/mongo/hash.js b/src/database/mongo/hash.jsindex 84d66660c0..d11cb0aacd 100644--- a/src/database/mongo/hash.js+++ b/src/database/mongo/hash.js@@ -1,5 +1,7 @@'use strict';+var pubsub = require('../../pubsub');+module.exports = function (db, module) {var helpers = module.helpers.mongo;@@ -16,6 +18,25 @@ module.exports = function (db, module) {cache.hits = 0;module.objectCache = cache;+ pubsub.on('mongo:hash:cache:del', function (key) {+ cache.del(key);+ });++ pubsub.on('mongo:hash:cache:reset', function () {+ cache.reset();+ });++ module.delObjectCache = function (key) {+ pubsub.publish('mongo:hash:cache:del', key);+ cache.del(key);+ };++ module.resetObjectCache = function () {+ pubsub.publish('mongo:hash:cache:reset');+ cache.reset();+ };++module.setObject = function (key, data, callback) {callback = callback || helpers.noop;if (!key || !data) {diff --git a/src/database/mongo/pubsub.js b/src/database/mongo/pubsub.jsindex 157d4652bd..83ff676294 100644--- a/src/database/mongo/pubsub.js+++ b/src/database/mongo/pubsub.js@@ -1,34 +1,8 @@'use strict';-var nconf = require('nconf');+var mubsub = require('mubsub');-module.exports = function (db, mongoModule) {- var pubsub;+var db = require('../mongo');+var client = mubsub(db.client);- if (!nconf.get('redis')) {- var mubsub = require('mubsub');- var client = mubsub(db);- pubsub = client.channel('pubsub');- mongoModule.pubsub = pubsub;- } else {- pubsub = require('../../pubsub');- }-- pubsub.on('mongo:hash:cache:del', function (key) {- mongoModule.objectCache.del(key);- });-- pubsub.on('mongo:hash:cache:reset', function () {- mongoModule.objectCache.reset();- });-- mongoModule.delObjectCache = function (key) {- pubsub.publish('mongo:hash:cache:del', key);- mongoModule.objectCache.del(key);- };-- mongoModule.resetObjectCache = function () {- pubsub.publish('mongo:hash:cache:reset');- mongoModule.objectCache.reset();- };-};+module.exports = client.channel('pubsub');diff --git a/src/database/redis.js b/src/database/redis.jsindex 55037393cb..e88663cf70 100644--- a/src/database/redis.js+++ b/src/database/redis.js@@ -50,7 +50,6 @@ redisModule.init = function (callback) {require('./redis/sets')(redisClient, redisModule);require('./redis/sorted')(redisClient, redisModule);require('./redis/list')(redisClient, redisModule);- require('./redis/pubsub')(redisClient, redisModule);callback();});diff --git a/src/database/redis/pubsub.js b/src/database/redis/pubsub.jsindex 3daf0f40cc..f7724bb016 100644--- a/src/database/redis/pubsub.js+++ b/src/database/redis/pubsub.js@@ -7,10 +7,10 @@ var EventEmitter = require('events').EventEmitter;var channelName;-var PubSub = function (redisModule) {+var PubSub = function (db) {var self = this;- var subClient = redisModule.connect();- this.pubClient = redisModule.connect();+ var subClient = db.connect();+ this.pubClient = db.connect();channelName = 'db:' + nconf.get('redis:database') + 'pubsub_channel';subClient.subscribe(channelName);@@ -35,6 +35,7 @@ PubSub.prototype.publish = function (event, data) {this.pubClient.publish(channelName, JSON.stringify({ event: event, data: data }));};-module.exports = function (redisClient, redisModule) {- redisModule.pubsub = new PubSub(redisModule);+module.exports = function () {+ var db = require('../redis');+ return new PubSub(db);};diff --git a/src/pubsub.js b/src/pubsub.jsindex 2364612b88..270ae37bf8 100644--- a/src/pubsub.js+++ b/src/pubsub.js@@ -32,9 +32,9 @@ function get() {pubsub = new EventEmitter();pubsub.publish = pubsub.emit.bind(pubsub);} else if (nconf.get('redis')) {- pubsub = require('./database/redis').pubsub;- } else {- pubsub = require('./database').pubsub;+ pubsub = require('./database/redis/pubsub');+ } else if (nconf.get('mongo')) {+ pubsub = require('./database/mongo/pubsub');}if (!pubsub) {