From 7daacc50bbdbf9c9569dd08f83a2671af465094c Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Mon, 9 Apr 2018 17:45:47 +0200 Subject: [PATCH 1/2] queues: Add an index on PlaylistSong.state --- .../queues/migrations/0006_state_db_index.py | 18 ++++++++++++++++++ marietje/queues/models.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 marietje/queues/migrations/0006_state_db_index.py diff --git a/marietje/queues/migrations/0006_state_db_index.py b/marietje/queues/migrations/0006_state_db_index.py new file mode 100644 index 0000000..c14dfec --- /dev/null +++ b/marietje/queues/migrations/0006_state_db_index.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.4 on 2018-04-09 15:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('queues', '0005_playlistsong_played_at'), + ] + + operations = [ + migrations.AlterField( + model_name='playlistsong', + name='state', + field=models.IntegerField(db_index=True, default=0), + ), + ] diff --git a/marietje/queues/models.py b/marietje/queues/models.py index 8944dfa..75bb015 100644 --- a/marietje/queues/models.py +++ b/marietje/queues/models.py @@ -35,7 +35,7 @@ class PlaylistSong(models.Model): # 1: Playing. # 2: Played. # 3: Cancelled. - state = models.IntegerField(default=0) + state = models.IntegerField(default=0, db_index=True) def move_up(self): other_song = PlaylistSong.objects.filter(playlist=self.playlist, id__lt=self.id)\ From dfd4752dea54a0219e2642341b2a4b9f580866ac Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Mon, 9 Apr 2018 18:06:12 +0200 Subject: [PATCH 2/2] Use southern style queue limit --- marietje/marietje/settings.py | 4 ++-- marietje/queues/models.py | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/marietje/marietje/settings.py b/marietje/marietje/settings.py index a2b8b5d..f365330 100644 --- a/marietje/marietje/settings.py +++ b/marietje/marietje/settings.py @@ -112,12 +112,12 @@ LOGOUT_REDIRECT_URL = '/' BERTHA_HOST = ('bach.science.ru.nl', 1234) MAIL_FROM = 'marietje@marietje.science.ru.nl' -MAX_MINUTES_IN_A_ROW = 20 +MAX_MINUTES_IN_A_ROW = 45 # Time range (dependent on timezone specified) when MAX_MINUTES_IN_A_ROW is in effect. LIMIT_HOURS = (12, 13) LIMIT_MINUTES = (15, 45) -LIMIT_ALWAYS = 45 +LIMIT_ALWAYS = True CONTACT_EMAIL = 'marietje@science.ru.nl' diff --git a/marietje/queues/models.py b/marietje/queues/models.py index 75bb015..9f8c5db 100644 --- a/marietje/queues/models.py +++ b/marietje/queues/models.py @@ -112,13 +112,7 @@ class Queue(models.Model): def request(self, song, user): playlist_songs = PlaylistSong.objects.filter(playlist=self.playlist, state=0).order_by('id') - - seconds_in_a_row = 0 - for playlist_song in playlist_songs: - if playlist_song.user != user: - seconds_in_a_row = 0 - else: - seconds_in_a_row += playlist_song.song.duration + seconds_in_a_row = sum(ps.song.duration for ps in playlist_songs if ps.user == user) now = timezone.now() if not user.is_superuser: