def METHOD_NAME(addons, **kw):
    if isinstance(addons, int):  # Got passed a single addon id.
        addons = [addons]
    log.info(
        '[%s@%s] Updating total reviews and average ratings.'
        % (len(addons), METHOD_NAME.rate_limit)
    )
    addon_objs = list(Addon.objects.filter(pk__in=addons))
    text_qs = (
        Rating.without_replies.all()
        .filter(addon__in=addons, is_latest=True)
        .exclude(body=None)
        .values('addon')  # Group by addon id.
        .annotate(count=Count('addon'))
        .order_by()
    )
    text_stats = {x['addon']: x['count'] for x in text_qs}
    grouped_qs = (
        Rating.without_replies.all()
        .filter(addon__in=addons, is_latest=True)
        .values_list('addon_id', 'rating')
        .annotate(Count('rating'))
        .order_by()
    )
    grouped_counts = defaultdict(dict)
    for addon_id, rating, count in grouped_qs:
        grouped_counts[addon_id][rating] = count
    for addon in addon_objs:
        counts = grouped_counts.get(addon.id, {})
        total = sum(count for score, count in counts.items() if score)
        average = (
            round(
                sum(score * count for score, count in counts.items() if score and count)
                / total,
                4,
            )
            if total
            else 0
        )
        reviews_with_text = text_stats.get(addon.pk, 0)
        addon.update(
            total_ratings=total,
            average_rating=average,
            text_ratings_count=reviews_with_text,
        )
        # Update grouped ratings
        RatingAggregate.objects.update_or_create(
            addon=addon,
            defaults={f'count_{idx}': counts.get(idx, 0) for idx in range(1, 6)},
        )
    # Delay bayesian calculations to avoid slave lag.
    addon_bayesian_rating.apply_async(args=addons, countdown=5)