Skip to content

Commit 53baa05

Browse files
committed
Less SQL queries for per-document page
- Legacy-Id: 1944
1 parent 1916782 commit 53baa05

4 files changed

Lines changed: 29 additions & 35 deletions

File tree

ietf/idrfc/idrfc_wrapper.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,15 @@ def _init(self):
547547
ads = set()
548548

549549
positions = []
550+
all_comments = self.ballot.comments.all().select_related('ad')
550551
for p in self.ballot.positions.all().select_related('ad'):
551-
po = create_position_object(self.ballot, p)
552+
po = create_position_object(self.ballot, p, all_comments)
552553
#if not self.ballot_active:
553554
# if 'is_old_ad' in po:
554555
# del po['is_old_ad']
555556
ads.add(str(p.ad))
556557
positions.append(po)
557-
for c in self.ballot.comments.all().select_related('ad'):
558+
for c in all_comments:
558559
if (str(c.ad) not in ads) and c.ad.is_current_ad():
559560
positions.append({'has_text':True,
560561
'comment_text':c.text,
@@ -620,7 +621,7 @@ def position_to_string(position):
620621
p = "No Record"
621622
return p
622623

623-
def create_position_object(ballot, position):
624+
def create_position_object(ballot, position, all_comments):
624625
positions = {"yes":"Yes",
625626
"noobj":"No Objection",
626627
"discuss":"Discuss",
@@ -640,15 +641,16 @@ def create_position_object(ballot, position):
640641
if len(was) > 0:
641642
r['old_positions'] = was
642643

643-
try:
644-
comment = ballot.comments.get(ad=position.ad)
645-
if comment and comment.text:
646-
r['has_text'] = True
647-
r['comment_text'] = comment.text
648-
r['comment_date'] = comment.date
649-
r['comment_revision'] = str(comment.revision)
650-
except IESGComment.DoesNotExist:
651-
pass
644+
comment = None
645+
for c in all_comments:
646+
if c.ad == position.ad:
647+
comment = c
648+
break
649+
if comment and comment.text:
650+
r['has_text'] = True
651+
r['comment_text'] = comment.text
652+
r['comment_date'] = comment.date
653+
r['comment_revision'] = str(comment.revision)
652654

653655
if p == "Discuss":
654656
try:

ietf/idrfc/views_doc.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,11 @@ def document_main_rfc(request, rfc_number):
8181
"rfc"+str(rfc_number)+",html",
8282
os.path.join(settings.RFC_PATH, "rfc"+str(rfc_number)+".txt"))
8383

84-
if doc.in_ietf_process() and doc.ietf_process.has_iesg_ballot():
85-
ballot = doc.ietf_process.iesg_ballot()
86-
else:
87-
ballot = None
88-
89-
history = _get_history(doc)
84+
history = _get_history(doc, None)
9085

9186
return render_to_response('idrfc/doc_main_rfc.html',
9287
{'content1':content1, 'content2':content2,
93-
'doc':doc, 'info':info, 'ballot':ballot,
88+
'doc':doc, 'info':info,
9489
'history':history},
9590
context_instance=RequestContext(request));
9691

@@ -130,22 +125,17 @@ def document_main(request, name):
130125
str(name)+","+str(id.revision)+",html",
131126
os.path.join(settings.INTERNET_DRAFT_PATH, name+"-"+id.revision+".txt"))
132127

133-
if doc.in_ietf_process() and doc.ietf_process.has_iesg_ballot():
134-
ballot = doc.ietf_process.iesg_ballot()
135-
else:
136-
ballot = None
137-
138128
versions = _get_versions(id)
139-
history = _get_history(doc)
129+
history = _get_history(doc, versions)
140130

141131
return render_to_response('idrfc/doc_main_id.html',
142132
{'content1':content1, 'content2':content2,
143-
'doc':doc, 'info':info, 'ballot':ballot,
133+
'doc':doc, 'info':info,
144134
'versions':versions, 'history':history},
145135
context_instance=RequestContext(request));
146136

147137
# doc is either IdWrapper or RfcWrapper
148-
def _get_history(doc):
138+
def _get_history(doc, versions):
149139
results = []
150140
if doc.is_id_wrapper:
151141
comments = DocumentComment.objects.filter(document=doc.tracker_id)
@@ -159,12 +149,12 @@ def _get_history(doc):
159149
info['textSnippet'] = truncatewords_html(format_textarea(fill(info['text'], 80)), 25)
160150
info['snipped'] = info['textSnippet'][-3:] == "..."
161151
results.append({'comment':comment, 'info':info, 'date':comment.datetime(), 'is_com':True})
162-
if doc.is_id_wrapper:
163-
versions = _get_versions(doc._draft, False)
164-
versions.reverse()
152+
if doc.is_id_wrapper and versions:
165153
for v in versions:
166-
v['is_rev'] = True
167-
results.append(v)
154+
if v['draft_name'] == doc.draft_name:
155+
v = dict(v) # copy it, since we're modifying datetimes later
156+
v['is_rev'] = True
157+
results.insert(0, v)
168158
if doc.is_id_wrapper and doc.draft_status == "Expired" and doc._draft.expiration_date:
169159
results.append({'is_text':True, 'date':doc._draft.expiration_date, 'text':'Draft expired'})
170160
if doc.is_rfc_wrapper:

ietf/templates/idrfc/doc_main.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ <h1 style="margin-top:0;">{% block doc_h1 %}{% endblock %}</h1>
7070
<div id="mytabs" class="yui-navset">
7171
<ul class="yui-nav">
7272
<li class="selected"><a href="#doc"><em>Document</em></a></li>
73-
<li {% if not ballot %}class="disabled" {%endif%}><a href="#ballot"><em>IESG Evaluation Record</em></a></li>
73+
<li{% if doc.in_ietf_process and doc.ietf_process.has_iesg_ballot %}{%else%} class="disabled"{%endif%}><a href="#ballot"><em>IESG Evaluation Record</em></a></li>
7474
<li {% if doc.in_ietf_process and doc.ietf_process.has_iesg_ballot %}{%else%}class="disabled" {%endif%}><a href="#writeup"><em>IESG Writeups</em></a></li>
7575
<li><a href="#history"><em>History</em></a></li>
7676
</ul>
@@ -84,10 +84,12 @@ <h1 style="margin-top:0;">{% block doc_h1 %}{% endblock %}</h1>
8484

8585
<div id="ballot">
8686
<div id="ballot_content">
87-
{% if ballot %}
87+
{% if doc.in_ietf_process and doc.ietf_process.has_iesg_ballot %}
8888
{% with 1 as doc_ballot_edit_button %}
89+
{% with doc.ietf_process.iesg_ballot as ballot %}
8990
{% include "idrfc/doc_ballot.html" %}
9091
{% endwith %}
92+
{% endwith %}
9193
{% endif %}
9294
</div>
9395
</div>

ietf/templates/idrfc/doc_main_id.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<tr><td>State:</td><td>
4444
{{ doc.friendly_state|safe }}
4545
{% if doc.rfc_editor_state %}<br />RFC Editor State: <a href="http://www.rfc-editor.org/queue2.html#{{doc.draft_name}}">{{ doc.rfc_editor_state|escape }}</a>{% endif %}
46-
{% if doc.replaces %}<br />Replaces {% for rep in doc.replaces %}<a href="/doc/{{rep}}/">{{rep}}</a> {% endfor %}{% endif %}
46+
{% with doc.replaces as r %}{% if r %}<br />Replaces {% for rep in r %}<a href="/doc/{{rep}}/">{{rep}}</a> {% endfor %}{% endif %}{% endwith %}
4747
</td></tr>
4848

4949
<tr><td>Intended status:</td><td>{% if doc.in_ietf_process %}{{ doc.ietf_process.intended_maturity_level|default:"-" }}{% else %}-{%endif%}</td></tr>

0 commit comments

Comments
 (0)