Created
December 10, 2010 11:23
-
-
Save chapel/736101 to your computer and use it in GitHub Desktop.
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
function stats(col, rand) { | |
if (!statStore[col]) { | |
db.get(col+'-stats', function(err, data){ | |
if (err) var data = {} | |
else data = JSON.parse(data) | |
if (data[rand]) data[rand]++ | |
else data[rand] = 1 | |
statStore[col] = data | |
setInterval(db.set(col+'-stats', JSON.stringify(statStore[col]), function(err){ | |
statStore[col] = false | |
if (err) console.log('Error setting stats for '+req.params.col) | |
}), 10*1000) | |
}) | |
} else { | |
var data = statStore[col] | |
if (data[rand]) data[rand]++ | |
else data[rand] = 1 | |
statStore[col] = data | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment