X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/92aff1148db7b03f585dbe204abda452a402c20c..cd3e03effc20790582d5ae6e8f2c1597c49ce31e:/contrib/shipherd/models.py?ds=sidebyside diff --git a/contrib/shipherd/models.py b/contrib/shipherd/models.py index 2eacc89..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) @@ -169,7 +170,7 @@ class Navigation(Entity): objects = NavigationManager() node = models.ForeignKey(Node, related_name='navigation_set', help_text="Be available as navigation for this node.") - key = models.CharField(max_length=255, validators=[RegexValidator("\w+")], help_text="Must contain one or more alphanumeric characters or underscores.") + key = models.CharField(max_length=255, validators=[RegexValidator("\w+")], help_text="Must contain one or more alphanumeric characters or underscores.", db_index=True) depth = models.PositiveSmallIntegerField(default=DEFAULT_NAVIGATION_DEPTH, validators=[MinValueValidator(1)], help_text="Defines the maximum display depth of this navigation.") def __init__(self, *args, **kwargs):