task for updating collection metadata
This commit is contained in:
Родитель
02f92c9f4a
Коммит
3ece628919
|
@ -56,6 +56,8 @@ class Collection(amo.models.ModelBase):
|
||||||
upvotes = models.PositiveIntegerField(default=0)
|
upvotes = models.PositiveIntegerField(default=0)
|
||||||
downvotes = models.PositiveIntegerField(default=0)
|
downvotes = models.PositiveIntegerField(default=0)
|
||||||
rating = models.FloatField(default=0)
|
rating = models.FloatField(default=0)
|
||||||
|
all_personas = models.BooleanField(default=False,
|
||||||
|
help_text='Does this collection only contain personas?')
|
||||||
|
|
||||||
addons = models.ManyToManyField(Addon, through='CollectionAddon',
|
addons = models.ManyToManyField(Addon, through='CollectionAddon',
|
||||||
related_name='collections')
|
related_name='collections')
|
||||||
|
|
|
@ -8,8 +8,9 @@ from celery.decorators import task
|
||||||
# from easy_thumbnails import processors
|
# from easy_thumbnails import processors
|
||||||
# from PIL import Image
|
# from PIL import Image
|
||||||
|
|
||||||
|
import amo
|
||||||
from . import cron # Pull in tasks run through cron.
|
from . import cron # Pull in tasks run through cron.
|
||||||
from .models import Collection, CollectionVote
|
from .models import Collection, CollectionAddon, CollectionVote
|
||||||
|
|
||||||
log = logging.getLogger('z.task')
|
log = logging.getLogger('z.task')
|
||||||
|
|
||||||
|
@ -35,3 +36,18 @@ def collection_votes(*ids):
|
||||||
# os.remove(src)
|
# os.remove(src)
|
||||||
# except Exception, e:
|
# except Exception, e:
|
||||||
# log.error("Error saving collection icon: %s" % e)
|
# log.error("Error saving collection icon: %s" % e)
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def collection_meta(*ids):
|
||||||
|
log.info('[%s@%s] Updating collection metadata.' %
|
||||||
|
(len(ids), collection_meta.rate_limit))
|
||||||
|
qs = (CollectionAddon.objects.filter(collection__in=ids)
|
||||||
|
.values_list('collection'))
|
||||||
|
counts = dict(qs.annotate(Count('id')))
|
||||||
|
persona_counts = dict(qs.filter(addon__type=amo.ADDON_PERSONA)
|
||||||
|
.annotate(Count('id')))
|
||||||
|
for c in Collection.objects.filter(id__in=ids):
|
||||||
|
c.addon_count = counts.get(c.id, 0)
|
||||||
|
c.all_personas = c.addon_count == persona_counts.get(c.id, None)
|
||||||
|
c.save()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `collections`
|
||||||
|
ADD `all_personas` bool DEFAULT False;
|
Загрузка…
Ссылка в новой задаче