Skip to content

Instantly share code, notes, and snippets.

@Streemo
Created July 28, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Streemo/e3a54ff724c2e9a3de8218c5756abf31 to your computer and use it in GitHub Desktop.
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`
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