random clip sort
This commit is contained in:
parent
cdd5976d32
commit
8511769885
3 changed files with 14 additions and 10 deletions
|
@ -115,7 +115,6 @@ attrs = {
|
||||||
'aspect_ratio': models.FloatField(default=0),
|
'aspect_ratio': models.FloatField(default=0),
|
||||||
|
|
||||||
'item': models.ForeignKey('item.Item', related_name='clips'),
|
'item': models.ForeignKey('item.Item', related_name='clips'),
|
||||||
'random': models.BigIntegerField(default=0, db_index=True, null=True),
|
|
||||||
|
|
||||||
#seconds
|
#seconds
|
||||||
'start': models.FloatField(default=-1, db_index=True),
|
'start': models.FloatField(default=-1, db_index=True),
|
||||||
|
@ -139,3 +138,7 @@ for name in settings.CONFIG['clipLayers']:
|
||||||
|
|
||||||
Clip = type('Clip', (MetaClip,models.Model), attrs)
|
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)
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ def order_query(qs, sort):
|
||||||
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
|
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
|
||||||
'duration', 'sortvalue', 'videoRatio',
|
'duration', 'sortvalue', 'videoRatio',
|
||||||
'director', 'title',
|
'director', 'title',
|
||||||
'random')
|
'random__random')
|
||||||
key = {
|
key = {
|
||||||
'id': 'public_id',
|
'id': 'public_id',
|
||||||
'in': 'start',
|
'in': 'start',
|
||||||
|
@ -50,6 +50,7 @@ def order_query(qs, sort):
|
||||||
'position': 'start',
|
'position': 'start',
|
||||||
'text': 'sortvalue',
|
'text': 'sortvalue',
|
||||||
'videoRatio': 'aspect_ratio',
|
'videoRatio': 'aspect_ratio',
|
||||||
|
'random': 'random__random',
|
||||||
}.get(e['key'], e['key'])
|
}.get(e['key'], e['key'])
|
||||||
if key.startswith('clip:'):
|
if key.startswith('clip:'):
|
||||||
key = e['key'][len('clip:'):]
|
key = e['key'][len('clip:'):]
|
||||||
|
|
|
@ -29,14 +29,14 @@ def update_random_sort():
|
||||||
|
|
||||||
def update_random_clip_sort():
|
def update_random_clip_sort():
|
||||||
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
||||||
random.seed()
|
from django.db import connection, transaction
|
||||||
from clip.models import Clip
|
cursor = connection.cursor()
|
||||||
ids = [f['id'] for f in Clip.objects.values('id')]
|
cursor.execute('DROP TABLE clip_random;')
|
||||||
random.shuffle(ids)
|
cursor.execute('CREATE TABLE "clip_random" AS SELECT id AS clip_id, row_number() OVER (ORDER BY random()) AS random FROM "clip_clip"')
|
||||||
n = 1
|
cursor.execute('ALTER TABLE "clip_random" ADD UNIQUE ("clip_id")')
|
||||||
for i in ids:
|
cursor.execute('CREATE INDEX "clip_random_clip_id_idx" ON "clip_random" ("clip_id")')
|
||||||
Clip.objects.filter(pk=i).update(random=n)
|
cursor.execute('CREATE INDEX "clip_random_random_idx" ON "clip_random" ("random")')
|
||||||
n += 1
|
transaction.commit_unless_managed()
|
||||||
|
|
||||||
@task(ignore_results=True, queue='default')
|
@task(ignore_results=True, queue='default')
|
||||||
def update_poster(itemId):
|
def update_poster(itemId):
|
||||||
|
|
Loading…
Reference in a new issue