Eliminated (Generic)ForeignKey evaluations in shipherd's NavigationManager.update_cac...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Wed, 22 Jun 2011 15:48:31 +0000 (11:48 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Wed, 22 Jun 2011 15:48:31 +0000 (11:48 -0400)
philo/contrib/shipherd/models.py
philo/models/nodes.py
philo/templatetags/nodes.py

index 429faaa..de9a869 100644 (file)
@@ -163,12 +163,12 @@ class NavigationManager(models.Manager):
                
                # A distinct query is not strictly necessary. TODO: benchmark the efficiency
                # with/without distinct.
-               targets = list(Node.objects.filter(pk__in=target_pks).distinct())
+               targets = dict([(n.pk, n) for n in Node.objects.filter(pk__in=target_pks).distinct()])
                
                for cache in caches:
                        for item in cache['items']:
                                if item.target_node_id:
-                                       item.target_node = targets[targets.index(item.target_node)]
+                                       item.target_node = targets[item.target_node_id]
        
        def clear_cache(self):
                """Clears the manager's entire navigation cache."""
index 5b8b8ed..9309a42 100644 (file)
@@ -39,8 +39,8 @@ class Node(SlugTreeEntity):
        @property
        def accepts_subpath(self):
                """A property shortcut for :attr:`self.view.accepts_subpath <View.accepts_subpath>`"""
-               if self.view:
-                       return self.view.accepts_subpath
+               if self.view_object_id and self.view_content_type_id:
+                       return ContentType.objects.get_for_id(self.view_content_type_id).model_class().accepts_subpath
                return False
        
        def handles_subpath(self, subpath):
@@ -126,7 +126,7 @@ class View(Entity):
        #: A generic relation back to nodes.
        nodes = generic.GenericRelation(Node, content_type_field='view_content_type', object_id_field='view_object_id')
        
-       #: Property or attribute which defines whether this :class:`View` can handle subpaths. Default: ``False``
+       #: An attribute on the class which defines whether this :class:`View` can handle subpaths. Default: ``False``
        accepts_subpath = False
        
        def handles_subpath(self, subpath):
index 189fdd5..52da236 100644 (file)
@@ -39,7 +39,7 @@ class NodeURLNode(template.Node):
                if self.with_obj is None and self.view_name is None:
                        url = node.get_absolute_url()
                else:
-                       if not node.view.accepts_subpath:
+                       if not node.accepts_subpath:
                                return settings.TEMPLATE_STRING_IF_INVALID
                        
                        if self.with_obj is not None: