From b333f447f678fbad6a37dc5d0ad54173283c39d4 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 11 Nov 2011 00:27:14 +0100 Subject: [PATCH 1/2] use UTC by default, slow rebuild --- pandora/item/management/commands/rebuildcache.py | 5 ++++- pandora/settings.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pandora/item/management/commands/rebuildcache.py b/pandora/item/management/commands/rebuildcache.py index 7bd8d83ac..8600d02c2 100644 --- a/pandora/item/management/commands/rebuildcache.py +++ b/pandora/item/management/commands/rebuildcache.py @@ -3,6 +3,7 @@ import os from os.path import join, dirname, basename, splitext, exists +import time from django.core.management.base import BaseCommand, CommandError from django.conf import settings @@ -20,11 +21,13 @@ class Command(BaseCommand): def handle(self, **options): offset = 0 - chunk = 100 + chunk = 50 count = pos = models.Item.objects.count() while offset <= count: for i in models.Item.objects.all().order_by('id')[offset:offset+chunk]: print pos, i.itemId i.save() + time.sleep(1) #dont overload db pos -= 1 offset += chunk + time.sleep(30) #dont overload db diff --git a/pandora/settings.py b/pandora/settings.py index 16315ad48..59992bbec 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -24,7 +24,8 @@ MANAGERS = ADMINS # although not all choices may be available on all operating systems. # If running in a Windows environment this must be set to the same as your # system time zone. -TIME_ZONE = 'Europe/Berlin' +TIME_ZONE = 'UTC' + #TIME_ZONE = 'Asia/Kolkata' # Language code for this installation. All choices can be found here: From ccfa48e3e04b4c0a962110fee196ea4ebe897f9a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 11 Nov 2011 11:34:57 +0100 Subject: [PATCH 2/2] update timesaccessed sort value on access --- pandora/item/models.py | 2 ++ pandora/item/views.py | 8 ++------ pandora/user/views.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 8bf2aa286..8d66115de 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1206,6 +1206,8 @@ class Access(models.Model): self.accessed = 0 self.accessed += 1 super(Access, self).save(*args, **kwargs) + timesaccessed = Access.objects.filter(item=self.item).aggregate(Sum('accessed'))['accessed__sum'] + ItemSort.objects.filter(item=self.item).update(timesaccessed=timesaccessed) def __unicode__(self): if self.user: diff --git a/pandora/item/views.py b/pandora/item/views.py index cff821498..acf9d83f0 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -53,7 +53,6 @@ def _order_query(qs, sort, prefix='sort__'): key = { 'id': 'itemId', 'accessed': 'accessed__access', - 'viewed': 'accessed__access', }.get(e['key'], e['key']) if key not in ('accessed__access', 'accessed__accessed'): key = "%s%s" % (prefix, key) @@ -237,13 +236,10 @@ Positions def only_p_sums(m): r = {} for p in _p: - if p == 'viewed' and request.user.is_authenticated(): - value = m.accessed.filter(user=request.user).annotate(v=Max('access')) - r[p] = value.exists() and value[0].v or None - elif p == 'accessed': + if p == 'accessed': r[p] = m.a elif p == 'timesaccessed': - r[p] = m.sort.timesaccessed + r[p] = m.timesaccessed else: r[p] = m.json.get(p, '') if 'clip_qs' in query: diff --git a/pandora/user/views.py b/pandora/user/views.py index 388006e54..447a930a5 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -690,7 +690,7 @@ def setUI(request): else: request.session['ui'] = json.dumps(ui) - if data.get('item', False): + if data.get('item'): item = get_object_or_404_json(Item, itemId=data['item']) if request.user.is_authenticated(): access, created = Access.objects.get_or_create(item=item, user=request.user)