From fc066c21bf33a32131b72fb889462c083b5d13a8 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 2 Dec 2013 21:33:35 -0500 Subject: [PATCH] added upgrade for global keys --- src/upgrade.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++--- src/user.js | 4 ++-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/upgrade.js b/src/upgrade.js index 2fcac1b0b0..3ba15a97e2 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -16,7 +16,7 @@ var db = require('./database'), Upgrade.check = function(callback) { // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema - var latestSchema = new Date(2013, 10, 26).getTime(); + var latestSchema = new Date(2013, 11, 2).getTime(); RDB.get('schemaDate', function(err, value) { if (parseInt(value, 10) >= latestSchema) { @@ -184,7 +184,7 @@ Upgrade.upgrade = function(callback) { }, function(next) { thisSchemaDate = new Date(2013, 10, 26).getTime(); - if (schemaDate < thisSchemaDate || 1) { + if (schemaDate < thisSchemaDate) { categories.getAllCategories(0, function(err, categories) { function updateIcon(category, next) { @@ -214,7 +214,57 @@ Upgrade.upgrade = function(callback) { winston.info('[2013/11/26] Update to Category icons skipped.'); next(); } - } + }, + function(next) { + + function updateKeyToHash(key, next) { + RDB.get(key, function(err, value) { + RDB.hset('global', newKeys[key], value, next); + }); + } + + thisSchemaDate = new Date(2013, 11, 2).getTime(); + if (schemaDate < thisSchemaDate) { + + var keys = [ + 'global:next_user_id', + 'next_topic_id', + 'next_gid', + 'notifications:next_nid', + 'global:next_category_id', + 'global:next_message_id', + 'global:next_post_id', + 'usercount', + 'totaltopiccount', + 'totalpostcount' + ]; + + var newKeys = { + 'global:next_user_id':'nextUid', + 'next_topic_id':'nextTid', + 'next_gid':'nextGid', + 'notifications:next_nid':'nextNid', + 'global:next_category_id':'nextCid', + 'global:next_message_id':'nextMid', + 'global:next_post_id':'nextPid', + 'usercount':'userCount', + 'totaltopiccount':'topicCount', + 'totalpostcount':'postCount' + }; + + async.each(keys, updateKeyToHash, function(err) { + if(err) { + return next(err); + } + winston.info('[2013/12/2] Updated global keys to hash.'); + next(); + }); + + } else { + winston.info('[2013/12/2] Update to global keys skipped'); + next(); + } + }, // Add new schema updates here // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 12!!! ], function(err) { diff --git a/src/user.js b/src/user.js index 0c227052c3..3c05b4f49a 100644 --- a/src/user.js +++ b/src/user.js @@ -107,7 +107,7 @@ var bcrypt = require('bcrypt'), } plugins.fireHook('action:user.create', {uid: uid, username: username, email: email, picture: gravatar, timestamp: timestamp}); - db.incrObjectField('global', 'usercount'); + db.incrObjectField('global', 'userCount'); db.sortedSetAdd('users:joindate', timestamp, uid); db.sortedSetAdd('users:postcount', 0, uid); @@ -597,7 +597,7 @@ var bcrypt = require('bcrypt'), }; User.count = function(socket) { - db.getObjectField('global', 'usercount', function(err, count) { + db.getObjectField('global', 'userCount', function(err, count) { if(err) { return; }