Created
March 10, 2017 01:06
-
-
Save akhoury/37efd8daa69fcb68dd6ef9b6d6adbf55 to your computer and use it in GitHub Desktop.
to set lithium's negative viewcount to 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var nconf = require('nconf'); | |
var async = require('async'); | |
nconf.file({ file: path.join(__dirname, './config.json') }); | |
var dbType = nconf.get('database'); | |
var productionDbConfig = nconf.get(dbType); | |
nconf.set(dbType, productionDbConfig); | |
var db = require('./src/database'); | |
db.init(function() { | |
console.log('db.ready'); | |
var batch = require('./src/batch'); | |
batch.processSortedSet('topics:tid', function (ids, next) { | |
async.each(ids, function (id, next) { | |
console.log('processing tid ' + id); | |
async.waterfall([ | |
function (next) { | |
db.getObjectField('topic:' + id, 'viewcount', next); | |
}, | |
function (viewcount, next) { | |
viewcount = parseInt(viewcount, 10); | |
if (viewcount < 0) { | |
db.setObjectField('topic:' + id, 'viewcount', 0, next); | |
} else { | |
next(); | |
} | |
} | |
], next); | |
}, next); | |
}, {}, function () { | |
console.log('ALL DONE!'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment