def post_save()

in src/olympia/ratings/models.py [0:0]


    def post_save(sender, instance, created, **kwargs):
        from olympia.addons.models import update_search_index

        from . import tasks

        if kwargs.get('raw'):
            return

        undeleted = kwargs.get('undeleted')

        if not undeleted and not instance.deleted:
            action = 'New' if created else 'Edited'
            if instance.reply_to:
                log.info(f'{action} reply to {instance.reply_to_id}: {instance.pk}')
            else:
                log.info(f'{action} rating: {instance.pk}')

            # For new ratings, replies, and all edits by users we
            # want to insert a new ActivityLog.
            new_rating_or_edit = not instance.reply_to or not created
            if new_rating_or_edit:
                action = amo.LOG.ADD_RATING if created else amo.LOG.EDIT_RATING
                activity.log_create(action, instance.addon, instance)
            else:
                activity.log_create(amo.LOG.REPLY_RATING, instance.addon, instance)

            # For new ratings and new replies we want to send an email.
            if created:
                instance.send_notification_email()

        if created or undeleted:
            # Do this immediately synchronously so is_latest is correct before
            # we fire the aggregates task.
            instance.update_denormalized_fields()

        # Rating counts have changed, so run the task and trigger a reindex.
        tasks.addon_rating_aggregates.delay(instance.addon_id)
        update_search_index(instance.addon.__class__, instance.addon)