'Return:
the list of unique res.users ids having received this badge
the total number of time this badge was granted
the total number of users this badge was granted to'

@api.depends('owner_ids')
def _get_owners_info(self):

    self.env.cr.execute('\n                                                SELECT    badge_id,    count(user_id)    as    stat_count,\n                                                                count(distinct(user_id))    as    stat_count_distinct,\n                                                                array_agg(distinct(user_id))    as    unique_owner_ids\n                                                FROM    gamification_badge_user\n                                                WHERE    badge_id    in    %s\n                                                GROUP    BY    badge_id\n                                                ', [tuple(self.ids)])
    defaults = {'stat_count': 0, 'stat_count_distinct': 0, 'unique_owner_ids': []}
    mapping = {badge_id: {'stat_count': count, 'stat_count_distinct': distinct_count, 'unique_owner_ids': owner_ids} for (badge_id, count, distinct_count, owner_ids) in self.env.cr._obj}
    for badge in self:
        badge.update(mapping.get(badge.id, defaults))
