Skip to content

Commit f3d96e7

Browse files
committed
Fix comment handling for drafts not in idinternal; use select_related to reduce SQL queries
- Legacy-Id: 1919
1 parent 3cd0304 commit f3d96e7

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

ietf/idrfc/testurl.list

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
404 /doc/draft-ietf-aaa-diameter-api/_ballot.data
3939
# ballot does not exist
4040
404 /doc/draft-zeilenga-cldap/_ballot.data
41+
# comment with created_by=999
42+
200 /doc/draft-ietf-l3vpn-2547bis-mcast-bgp/
43+
# comment with created_by=0 (and no idinternal entry)
44+
200 /doc/draft-ietf-proto-wgdocument-states/
4145

4246
200 /doc/search/
4347
200 /doc/search/?rfcs=on&name=snmp

ietf/idrfc/views_doc.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from datetime import datetime, time
3535
from django.http import HttpResponse, Http404
3636
from django.shortcuts import render_to_response, get_object_or_404
37-
from ietf.idtracker.models import InternetDraft, IDInternal, BallotInfo
37+
from ietf.idtracker.models import InternetDraft, IDInternal, BallotInfo, DocumentComment
3838
from ietf.idrfc.models import RfcIndex, DraftVersions
3939
from ietf.idrfc.idrfc_wrapper import BallotWrapper, IdWrapper, RfcWrapper
4040
from ietf.idrfc import markup_txt
@@ -147,14 +147,18 @@ def document_main(request, name):
147147
# doc is either IdWrapper or RfcWrapper
148148
def _get_history(doc):
149149
results = []
150-
if doc._idinternal:
151-
for comment in doc._idinternal.public_comments():
152-
info = {}
153-
info['text'] = comment.comment_text
154-
info['by'] = comment.get_fullname()
155-
info['textSnippet'] = truncatewords_html(format_textarea(fill(info['text'], 80)), 25)
156-
info['snipped'] = info['textSnippet'][-3:] == "..."
157-
results.append({'comment':comment, 'info':info, 'date':comment.datetime(), 'is_com':True})
150+
if doc.is_id_wrapper:
151+
comments = DocumentComment.objects.filter(document=doc.tracker_id)
152+
else:
153+
# note: DocumentComment.rfc_flag is often wrong; avoid it
154+
comments = DocumentComment.objects.filter(document=doc.rfc_number)
155+
for comment in comments.order_by('-date','-time','-id').filter(public_flag=1).select_related('created_by'):
156+
info = {}
157+
info['text'] = comment.comment_text
158+
info['by'] = comment.get_fullname()
159+
info['textSnippet'] = truncatewords_html(format_textarea(fill(info['text'], 80)), 25)
160+
info['snipped'] = info['textSnippet'][-3:] == "..."
161+
results.append({'comment':comment, 'info':info, 'date':comment.datetime(), 'is_com':True})
158162
if doc.is_id_wrapper:
159163
versions = _get_versions(doc._draft, False)
160164
versions.reverse()

0 commit comments

Comments
 (0)