diff --git a/ietf/doc/models.py b/ietf/doc/models.py index a1b25de30..ec7adb628 100644 --- a/ietf/doc/models.py +++ b/ietf/doc/models.py @@ -122,7 +122,7 @@ class DocumentInfo(models.Model): if not hasattr(self, "state_cache") or self.state_cache == None: self.state_cache = {} - for s in self.states.all().select_related("type"): + for s in self.states.all(): self.state_cache[s.type_id] = s return self.state_cache.get(state_type, None) @@ -357,7 +357,7 @@ class Document(DocumentInfo): iesg_state = self.get_state("draft-iesg") iesg_state_summary = None if iesg_state: - iesg_substate = self.tags.filter(slug__in=IESG_SUBSTATE_TAGS) + iesg_substate = [t for t in self.tags.all() if t.slug in IESG_SUBSTATE_TAGS] # There really shouldn't be more than one tag in iesg_substate, but this will do something sort-of-sensible if there is iesg_state_summary = iesg_state.name if iesg_substate: diff --git a/ietf/doc/views_search.py b/ietf/doc/views_search.py index 1762118a2..1cceff3d5 100644 --- a/ietf/doc/views_search.py +++ b/ietf/doc/views_search.py @@ -112,9 +112,7 @@ def wrap_value(v): def fill_in_search_attributes(docs): # fill in some attributes for the search results to save some - # hairy template code and avoid repeated SQL queries - remaining - # queries we don't handle here are mostly implicit many-to-many - # relations for which there is poor support in Django 1.2 + # hairy template code and avoid repeated SQL queries docs_dict = dict((d.pk, d) for d in docs) doc_ids = docs_dict.keys() @@ -304,7 +302,9 @@ def retrieve_search_results(form, all_types=False): # evaluate and fill in attribute results immediately to cut down # the number of queries - results = list(docs.select_related("states", "ad", "ad__person", "std_level", "intended_std_level", "group", "stream")[:MAX]) + docs = docs.select_related("ad", "ad__person", "std_level", "intended_std_level", "group", "stream") + docs = docs.prefetch_related("states__type", "tags") + results = list(docs[:MAX]) fill_in_search_attributes(results) diff --git a/ietf/idindex/index.py b/ietf/idindex/index.py index ec4745c69..3fded22d7 100644 --- a/ietf/idindex/index.py +++ b/ietf/idindex/index.py @@ -96,7 +96,9 @@ def file_types_for_drafts(): def all_id2_txt(): # this returns a lot of data so try to be efficient - drafts = Document.objects.filter(type="draft").exclude(name__startswith="rfc").order_by('name').select_related('group', 'group__parent', 'ad', 'ad__email', 'intended_std_level', 'shepherd', 'shepherd__email') + drafts = Document.objects.filter(type="draft").exclude(name__startswith="rfc").order_by('name') + drafts = drafts.select_related('group', 'group__parent', 'ad', 'ad__email', 'intended_std_level', 'shepherd', 'shepherd__email') + drafts = drafts.prefetch_related("states") rfc_aliases = dict(DocAlias.objects.filter(name__startswith="rfc", document__states=State.objects.get(type="draft", slug="rfc")).values_list("document_id", "name"))