fix clip random
This commit is contained in:
parent
2fe857d4fd
commit
3f02f6086a
3 changed files with 45 additions and 9 deletions
30
pandora/clip/migrations/0003_auto_20160219_1805.py
Normal file
30
pandora/clip/migrations/0003_auto_20160219_1805.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.2 on 2016-02-19 18:05
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('clip', '0002_auto_20160219_1537'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ClipRandom',
|
||||
fields=[
|
||||
('id', models.BigIntegerField(primary_key=True, serialize=False)),
|
||||
('clip', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='clip.Clip')),
|
||||
],
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='random',
|
||||
name='clip',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Random',
|
||||
),
|
||||
]
|
|
@ -59,7 +59,7 @@ class MetaClip(object):
|
|||
else:
|
||||
self.hue = self.saturation = self.lightness = 0
|
||||
self.volume = 0
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.duration != self.end - self.start:
|
||||
self.update_calculated_values()
|
||||
|
@ -215,7 +215,6 @@ for name in [k['id'] for k in settings.CONFIG['layers']]:
|
|||
|
||||
Clip = type('Clip', (MetaClip,models.Model), attrs)
|
||||
|
||||
class Random(models.Model):
|
||||
clip = models.ForeignKey(Clip, primary_key=True)
|
||||
random = models.BigIntegerField(db_index=True, null=True)
|
||||
|
||||
class ClipRandom(models.Model):
|
||||
id = models.BigIntegerField(primary_key=True)
|
||||
clip = models.OneToOneField(Clip)
|
||||
|
|
|
@ -34,10 +34,17 @@ def update_random_clip_sort():
|
|||
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
||||
with transaction.atomic():
|
||||
cursor = connection.cursor()
|
||||
cursor.execute('DROP TABLE clip_random;')
|
||||
cursor.execute('CREATE TABLE "clip_random" AS SELECT id AS clip_id, row_number() OVER (ORDER BY random()) AS random FROM "clip_clip"')
|
||||
cursor.execute('ALTER TABLE "clip_random" ADD UNIQUE ("clip_id")')
|
||||
cursor.execute('CREATE INDEX "clip_random_random" ON "clip_random" ("random")')
|
||||
for row in (
|
||||
'DROP TABLE clip_cliprandom',
|
||||
'CREATE TABLE "clip_cliprandom" AS SELECT id AS clip_id, row_number() OVER (ORDER BY random()) AS id FROM "clip_clip"',
|
||||
'ALTER TABLE "clip_cliprandom" ADD UNIQUE ("clip_id")',
|
||||
'ALTER TABLE "clip_cliprandom" ADD UNIQUE ("id")',
|
||||
'ALTER TABLE "clip_cliprandom" ALTER COLUMN "id" SET NOT NULL',
|
||||
'ALTER TABLE "clip_cliprandom" ALTER COLUMN "clip_id" SET NOT NULL',
|
||||
|
||||
):
|
||||
cursor.execute(row)
|
||||
|
||||
|
||||
@task(ignore_results=True, queue='default')
|
||||
def update_clips(public_id):
|
||||
|
|
Loading…
Reference in a new issue