Skip to content

Instantly share code, notes, and snippets.

@svasva
Last active December 21, 2015 15:48
Show Gist options
  • Save svasva/6329012 to your computer and use it in GitHub Desktop.
Save svasva/6329012 to your computer and use it in GitHub Desktop.
fetchHrates: (curr) ->
setHashrate = (userId, name, wrkName, hashrate) ->
sel =
userId: userId
wrkName: wrkName
currId: curr._id
if id = Hashrates.findOne(sel, {fields: {_id: 1}})?._id
Hashrates.update id, $set: {hashrate: hashrate, name: name}
else
Hashrates.insert
currId: curr._id
userId: userId
wrkName: wrkName
hashrate: hashrate
name: name
userNames = {}
userHrates = {}
for name, hashrate of hRates
[userId, wrkName] = name.split('.')
userNames[userId] ||= h.getNick(Meteor.users.findOne(userId))
userHrates[userId] ||= 0
userHrates[userId] += hashrate
setHashrate(userId, userNames[userId], wrkName, hashrate)
for userId, hashrate of userHrates
setHashrate(userId, userNames[userId], '__total__', hashrate)
sel =
currId: curr._id
userId: {$nin: _.keys(userHrates)}
Hashrates.update sel, {$set: {hashrate: 0}}, {multi: true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment