dfde30ba962305f6877e61ce256bbe54d6a785aa,ratings/models.py,,post_delete_rating,#,49
Before Change
try:
with transaction.atomic():
instance.sound.num_ratings = F("num_ratings") - 1
rating = SoundRating.objects.filter(
sound_id=instance.sound_id).aggregate(Avg("rating")).values()[0]
if not rating:
rating = 0
instance.sound.avg_rating = rating
instance.sound.save()
After Change
try:
with transaction.atomic():
instance.sound.num_ratings = F("num_ratings") - 1
avg_rating = SoundRating.objects.filter(
sound_id=instance.sound_id).aggregate(average_rating=Coalesce(Avg("rating"), 0))
rating = avg_rating["average_rating"]
instance.sound.avg_rating = rating
instance.sound.save()
except ObjectDoesNotExist:
pass
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 8
Instances
Project Name: MTG/freesound
Commit Name: dfde30ba962305f6877e61ce256bbe54d6a785aa
Time: 2017-11-20
Author: alastair.porter@upf.edu
File Name: ratings/models.py
Class Name:
Method Name: post_delete_rating
Project Name: MTG/freesound
Commit Name: c078fdf9c6ef6aaeabbcf6ac42e9e9e06097e641
Time: 2017-11-09
Author: alastair.porter@upf.edu
File Name: ratings/models.py
Class Name:
Method Name: update_num_ratings_on_post_insert
Project Name: MTG/freesound
Commit Name: c078fdf9c6ef6aaeabbcf6ac42e9e9e06097e641
Time: 2017-11-09
Author: alastair.porter@upf.edu
File Name: ratings/models.py
Class Name:
Method Name: post_delete_rating