Created
July 28, 2016 18:39
-
-
Save Streemo/e3a54ff724c2e9a3de8218c5756abf31 to your computer and use it in GitHub Desktop.
if many users included, don't do N `findOne` operations. Instead, do a single `find` followed by a `forEach`
This file contains 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
send(m){ | |
if (m.numbers){ | |
m.numbers.forEach((number)=>{ | |
this._sendSMS(m.text, number); | |
}) | |
} else { | |
let sentTo = []; | |
Devices.find({userId: {$in: m.users}}).forEach((device) => { | |
const devId = this._sendNotification(device, m.title, m.text, m.data); | |
devId && sentTo.push(devId) | |
}) | |
Devices.update({_id:{$in: sentTo}},{$set:{lastUsed: new Date()}}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment