add manage command to rebuild cache, only update cache after updating sort values
This commit is contained in:
parent
e37657436b
commit
0cdafdef9b
6 changed files with 41 additions and 6 deletions
0
pandora/item/management/__init__.py
Normal file
0
pandora/item/management/__init__.py
Normal file
0
pandora/item/management/commands/__init__.py
Normal file
0
pandora/item/management/commands/__init__.py
Normal file
29
pandora/item/management/commands/rebuildcache.py
Normal file
29
pandora/item/management/commands/rebuildcache.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
|
||||||
|
import os
|
||||||
|
from os.path import join, dirname, basename, splitext, exists
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
from ... import models
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""
|
||||||
|
rebuild sort/search cache for all items.
|
||||||
|
"""
|
||||||
|
help = 'listen to rabbitmq and execute encoding tasks.'
|
||||||
|
args = ''
|
||||||
|
|
||||||
|
def handle(self, **options):
|
||||||
|
offset = 0
|
||||||
|
chunk = 100
|
||||||
|
pos = models.Item.objects.count()
|
||||||
|
while offset <= models.Item.objects.count():
|
||||||
|
for i in models.Item.objects.all().order_by('id')[offset:offset+chunk]:
|
||||||
|
print pos, i.itemId
|
||||||
|
i.save()
|
||||||
|
pos -= 1
|
||||||
|
offset += chunk
|
|
@ -164,7 +164,6 @@ class Item(models.Model):
|
||||||
return '/%s' % self.itemId
|
return '/%s' % self.itemId
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.json = self.get_json()
|
|
||||||
self.oxdbId = self.oxdb_id()
|
self.oxdbId = self.oxdb_id()
|
||||||
|
|
||||||
if self.poster:
|
if self.poster:
|
||||||
|
@ -173,10 +172,11 @@ class Item(models.Model):
|
||||||
else:
|
else:
|
||||||
self.poster_height = 128
|
self.poster_height = 128
|
||||||
self.poster_width = 80
|
self.poster_width = 80
|
||||||
super(Item, self).save(*args, **kwargs)
|
|
||||||
self.update_find()
|
self.update_find()
|
||||||
self.update_sort()
|
self.update_sort()
|
||||||
self.update_facets()
|
self.update_facets()
|
||||||
|
self.json = self.get_json()
|
||||||
|
super(Item, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
self.delete_poster()
|
self.delete_poster()
|
||||||
|
@ -298,7 +298,9 @@ class Item(models.Model):
|
||||||
return layers
|
return layers
|
||||||
|
|
||||||
def get_json(self, fields=None):
|
def get_json(self, fields=None):
|
||||||
item = {}
|
item = {
|
||||||
|
'id': self.itemId
|
||||||
|
}
|
||||||
item.update(self.external_data)
|
item.update(self.external_data)
|
||||||
item.update(self.data)
|
item.update(self.data)
|
||||||
for key in site_config['keys'].keys():
|
for key in site_config['keys'].keys():
|
||||||
|
@ -490,10 +492,10 @@ class Item(models.Model):
|
||||||
value = self.get(source, None)
|
value = self.get(source, None)
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
value = datetime.strptime(value, '%Y-%m-%d')
|
value = datetime.strptime(value, '%Y-%m-%d')
|
||||||
setattr(s, '%s_desc'%name, value)
|
setattr(s, name, value)
|
||||||
if not value:
|
if not value:
|
||||||
value = datetime.strptime('9999-12-12', '%Y-%m-%d')
|
value = datetime.strptime('9999-12-12', '%Y-%m-%d')
|
||||||
setattr(s, name, value)
|
setattr(s, '%s_desc'%name, value)
|
||||||
|
|
||||||
#sort keys based on database, these will always be available
|
#sort keys based on database, these will always be available
|
||||||
s.itemId = self.itemId.replace('0x', 'xx')
|
s.itemId = self.itemId.replace('0x', 'xx')
|
||||||
|
|
|
@ -5,6 +5,7 @@ from __future__ import division, with_statement
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
from ox.django.fields import DictField
|
||||||
|
|
||||||
class List(models.Model):
|
class List(models.Model):
|
||||||
|
|
||||||
|
@ -16,6 +17,9 @@ class List(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
public = models.BooleanField(default=False)
|
public = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
query = DictField(default={})
|
||||||
|
|
||||||
items = models.ManyToManyField('item.Item', related_name='lists',
|
items = models.ManyToManyField('item.Item', related_name='lists',
|
||||||
through='ListItem')
|
through='ListItem')
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
{"id": "producer", "title": "Producer", "width": 180, "type": "person"},
|
{"id": "producer", "title": "Producer", "width": 180, "type": "person"},
|
||||||
{"id": "cinematographer", "title": "Cinematographer", "width": 180, "type": "person"},
|
{"id": "cinematographer", "title": "Cinematographer", "width": 180, "type": "person"},
|
||||||
{"id": "editor", "title": "Editor", "width": 180, "type": "person"},
|
{"id": "editor", "title": "Editor", "width": 180, "type": "person"},
|
||||||
{"id": "actor", "title": "Number of Actors", "width": 60, "type": "person"},
|
{"id": "numberofactors", "title": "Number of Actors", "width": 60, "key": "actor", "type": "length"},
|
||||||
{"id": "genre", "title": "Genre", "width": 120, "type": "string"},
|
{"id": "genre", "title": "Genre", "width": 120, "type": "string"},
|
||||||
{"id": "numberofkeywords", "title": "Number of Keywords", "width": 60, "key": "keyword", "type": "length"},
|
{"id": "numberofkeywords", "title": "Number of Keywords", "width": 60, "key": "keyword", "type": "length"},
|
||||||
{"id": "wordsinsummary", "title": "Words in Summary", "width": 60, "key": "summary", "type": "words"},
|
{"id": "wordsinsummary", "title": "Words in Summary", "width": 60, "key": "summary", "type": "words"},
|
||||||
|
|
Loading…
Reference in a new issue