Bug 1025805 multiple RIDs over time

Could you move this to the very top of this function, before you run the database query?