From be8d9be832b4b82e098a319100ba0675c689ad96 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 4 Oct 2013 10:27:32 -0400 Subject: [PATCH] flushed out upgrade path for notifications --- src/upgrade.js | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/upgrade.js b/src/upgrade.js index b060c532c5..153c7c0399 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -11,20 +11,52 @@ Upgrade.upgrade = function() { function(next) { RDB.hget('notifications:1', 'score', function(err, score) { if (score) { - winston.info('[2013/10/03] Updating Notifications'); - RDB.keys('uid:*:notifications:*', function(err, keys) { - async.each(keys, function(key, next) { - RDB.zrange(key, 0, -1, function(err, nids) { - async.each(nids, function(nid, next) { - notifications.get(nid, function(notif_data) { - RDB.zadd(key, notif_data.datetime, nid, next); + async.series([ + function(next) { + RDB.keys('uid:*:notifications:flag', function(err, keys) { + if (keys.length > 0) { + winston.info('[2013/10/03] Removing deprecated Notification Flags'); + async.each(keys, function(key, next) { + RDB.del(key, next); + }, next); + } else { + winston.info('[2013/10/03] No Notification Flags found. Good.'); + next(); + } + }); + }, + function(next) { + winston.info('[2013/10/03] Updating Notifications'); + RDB.keys('uid:*:notifications:*', function(err, keys) { + async.each(keys, function(key, next) { + RDB.zrange(key, 0, -1, function(err, nids) { + async.each(nids, function(nid, next) { + notifications.get(nid, function(notif_data) { + RDB.zadd(key, notif_data.datetime, nid, next); + }); + }, next); }); }, next); }); - }, next); - }); + }, + function(next) { + RDB.keys('notifications:*', function(err, keys) { + if (keys.length > 0) { + winston.info('[2013/10/03] Removing Notification Scores'); + async.each(keys, function(key, next) { + if (key === 'notifications:next_nid') return next(); + RDB.hdel(key, 'score', next); + }, next); + } else { + winston.info('[2013/10/03] No Notification Scores found. Good.'); + next(); + } + }); + } + ], next); } else { winston.info('[2013/10/03] Updates to Notifications skipped.'); + next(); } }); }