Skip to content

Instantly share code, notes, and snippets.

@klamping
Last active August 29, 2015 14:23
Show Gist options
  • Save klamping/e3fec0309489e84c3b9d to your computer and use it in GitHub Desktop.
Save klamping/e3fec0309489e84c3b9d to your computer and use it in GitHub Desktop.
hamster.fetch('char:Notifications', {}, function (err, res) {
if (err) throw err
var notifications = res.notifications;
// filter out all notifications w/o the right ids
var matchingType = _.filter(notifications, function (notification) {
return notification.typeID == 36 || notification.typeID == 37;
});
// convert that collection an array with just the keys
var typeKeys = _.keys(matchingType);
// get the cached notifications and gets an array of their ids
var cachedNotifications = 'stuff'; // pull data from redis
var notificationIds = _.pluck(cachedNotifications, 'Id');
// only keep the notification id's that don't already exist
var uniqueIds = _.difference(notificationIds, typeKeys);
// run shit on those ids
_.each(uniqueIds, function (id) {
hamster.fetch('char:NotificationTexts', {IDs: id}, function(err, res) {
if (err) throw err
// publish the notification to all subscribers
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment