From d0bfa7e89642d01cfa9204142a41d9f05efd4cb5 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 9 Feb 2011 16:34:58 -0500 Subject: [PATCH] Corrected penfield migration which introduces the feed_type column. Switched NavigationManager.update_targets_for() method to search for node pks instead of doing a JOIN - should be more efficient. Added check for node id before updating the target_node; this was causing an unwanted KeyError in cases where the NavigationItem had no target node. --- ...letterview_feed_type__add_field_newsletterview_ite.py | 2 +- contrib/shipherd/models.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/contrib/penfield/migrations/0003_auto__add_field_newsletterview_feed_type__add_field_newsletterview_ite.py b/contrib/penfield/migrations/0003_auto__add_field_newsletterview_feed_type__add_field_newsletterview_ite.py index 1f6d829..eae496e 100644 --- a/contrib/penfield/migrations/0003_auto__add_field_newsletterview_feed_type__add_field_newsletterview_ite.py +++ b/contrib/penfield/migrations/0003_auto__add_field_newsletterview_feed_type__add_field_newsletterview_ite.py @@ -9,7 +9,7 @@ class Migration(SchemaMigration): def forwards(self, orm): # Adding field 'NewsletterView.feed_type' - db.add_column('penfield_newsletterview', 'feed_type', self.gf('django.db.models.fields.CharField')(default='atom', max_length=50), keep_default=False) + db.add_column('penfield_newsletterview', 'feed_type', self.gf('django.db.models.fields.CharField')(default='application/atom+xml', max_length=50), keep_default=False) # Adding field 'NewsletterView.item_title_template' db.add_column('penfield_newsletterview', 'item_title_template', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='penfield_newsletterview_title_related', null=True, to=orm['philo.Template']), keep_default=False) diff --git a/contrib/shipherd/models.py b/contrib/shipherd/models.py index 8efc57a..654f5f8 100644 --- a/contrib/shipherd/models.py +++ b/contrib/shipherd/models.py @@ -148,18 +148,19 @@ class NavigationManager(models.Manager): # about that. TODO: Benchmark it. caches = self.__class__._cache[self.db][node].values() - items = [] + target_pks = set() for cache in caches: - items += cache['items'] + target_pks |= set([item.target_node_id for item in cache['items']]) # A distinct query is not strictly necessary. TODO: benchmark the efficiency # with/without distinct. - targets = list(Node.objects.filter(shipherd_navigationitem_related__in=items).distinct()) + targets = list(Node.objects.filter(pk__in=target_pks).distinct()) for cache in caches: for item in cache['items']: - item.target_node = targets[targets.index(item.target_node)] + if item.target_node_id: + item.target_node = targets[targets.index(item.target_node)] def clear_cache(self): self.__class__._cache.pop(self.db, None) -- 2.20.1