'Update the partially filled rules_by_user dict by fetching rules for
any newly joined users in the `member_event_ids` list.
Args:
ret_rules_by_user (dict): Partiallly filled dict of push rules. Gets
updated with any new rules.
member_event_ids (list): List of event ids for membership events that
have happened since the last time we filled rules_by_user
state_group: The state group we are currently computing push rules
for. Used when updating the cache.'

@defer.inlineCallbacks
def _update_rules_with_member_event_ids(self, ret_rules_by_user, member_event_ids, state_group, event):

    sequence = self.sequence
    rows = (yield self.store._simple_select_many_batch(table='room_memberships', column='event_id', iterable=member_event_ids.values(), retcols=('user_id', 'membership', 'event_id'), keyvalues={}, batch_size=500, desc='_get_rules_for_member_event_ids'))
    members = {row['event_id']: (row['user_id'], row['membership']) for row in rows}
    if (event.type == EventTypes.Member):
        for event_id in member_event_ids.itervalues():
            if (event_id == event.event_id):
                members[event_id] = (event.state_key, event.membership)
    if logger.isEnabledFor(logging.DEBUG):
        logger.debug('Found    members    %r:    %r', self.room_id, members.values())
    interested_in_user_ids = set((user_id for (user_id, membership) in members.itervalues() if (membership == Membership.JOIN)))
    logger.debug('Joined:    %r', interested_in_user_ids)
    if_users_with_pushers = (yield self.store.get_if_users_have_pushers(interested_in_user_ids, on_invalidate=self.invalidate_all_cb))
    user_ids = set((uid for (uid, have_pusher) in if_users_with_pushers.iteritems() if have_pusher))
    logger.debug('With    pushers:    %r', user_ids)
    users_with_receipts = (yield self.store.get_users_with_read_receipts_in_room(self.room_id, on_invalidate=self.invalidate_all_cb))
    logger.debug('With    receipts:    %r', users_with_receipts)
    for uid in users_with_receipts:
        if (uid in interested_in_user_ids):
            user_ids.add(uid)
    rules_by_user = (yield self.store.bulk_get_push_rules(user_ids, on_invalidate=self.invalidate_all_cb))
    ret_rules_by_user.update((item for item in rules_by_user.iteritems() if (item[0] is not None)))
    self.update_cache(sequence, members, ret_rules_by_user, state_group)
