Add a db_index on PlaylistSong.user

This commit is contained in:
Daan Sprenkels
2018-10-28 14:26:58 +01:00
parent 21522602bd
commit 383f12235a
2 changed files with 5 additions and 4 deletions

View File

@ -314,7 +314,7 @@ def mute(request):
@transaction.atomic @transaction.atomic
def upload_stats(user): def upload_stats(user):
q = PlaylistSong.objects.filter(user=user, song__deleted=False).aggregate( q = PlaylistSong.objects.filter(user=user, state=2, song__deleted=False).aggregate(
minutes_queued=Coalesce(Sum('song__duration'), Value(0))) minutes_queued=Coalesce(Sum('song__duration'), Value(0)))
q.update(Song.objects.filter(user=user, deleted=False).aggregate( q.update(Song.objects.filter(user=user, deleted=False).aggregate(
minutes_upload=Coalesce(Sum('duration'), Value(0)))) minutes_upload=Coalesce(Sum('duration'), Value(0))))

View File

@ -15,19 +15,20 @@ class PlaylistSong(models.Model):
Playlist, Playlist,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
blank=True, blank=True,
null=True null=True,
) )
song = models.ForeignKey( song = models.ForeignKey(
Song, Song,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
blank=True, blank=True,
null=True null=True,
) )
user = models.ForeignKey( user = models.ForeignKey(
settings.AUTH_USER_MODEL, settings.AUTH_USER_MODEL,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
blank=True, blank=True,
null=True null=True,
db_index=True,
) )
played_at = models.DateTimeField(blank=True, null=True) played_at = models.DateTimeField(blank=True, null=True)