Created
July 28, 2016 18:41
-
-
Save Streemo/01943bf8fa0a7239b15ed30203beed29 to your computer and use it in GitHub Desktop.
Instead of doing N findOne operations, do a single find operation. Could add some code to explicitly handle 1 vs. N, but it's cleaner to just use arrays for everything, including single elements.
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
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