summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2012-01-08 17:35:24 +0100
committerTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2012-01-08 17:35:24 +0100
commitb332d5d6b9f79491c2412989bc1e75679a9dc685 (patch)
treee1601b5f1778621018a48a517d9254ab18d269cc
parent5efcca3f1931f4a678c68404dcf1d592943ee2f8 (diff)
downloadaskbot-b332d5d6b9f79491c2412989bc1e75679a9dc685.tar.gz
askbot-b332d5d6b9f79491c2412989bc1e75679a9dc685.tar.bz2
askbot-b332d5d6b9f79491c2412989bc1e75679a9dc685.zip
Optimized the main page so that is uses only 5 sql question to fetch all necessary data
-rw-r--r--askbot/models/question.py6
-rw-r--r--askbot/skins/default/templates/widgets/question_summary.html7
2 files changed, 7 insertions, 6 deletions
diff --git a/askbot/models/question.py b/askbot/models/question.py
index 693ef814..660e5c4b 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -350,10 +350,12 @@ class Thread(models.Model):
"Creates a list of Tag names from the ``tagnames`` attribute."
return self.tagnames.split(u' ')
- def get_title(self):
+ def get_title(self, question=None):
+ if not question:
+ question = self._question_post() # allow for optimization if the caller has already fetched the question post for this thread
if self.closed:
attr = const.POST_STATUS['closed']
- elif self._question_post().deleted:
+ elif question.deleted:
attr = const.POST_STATUS['deleted']
else:
attr = None
diff --git a/askbot/skins/default/templates/widgets/question_summary.html b/askbot/skins/default/templates/widgets/question_summary.html
index e9bb08b6..db44e435 100644
--- a/askbot/skins/default/templates/widgets/question_summary.html
+++ b/askbot/skins/default/templates/widgets/question_summary.html
@@ -16,7 +16,7 @@
{% if thread.answer_count == 0 -%}
no-answers
{% else -%}
- {%- if thread.accepted_answer -%}
+ {%- if thread.accepted_answer_id -%} {# INFO: Use _id to not fetch the whole answer post #}
accepted
{%- else -%}
some-answers
@@ -24,7 +24,7 @@
{%- endif -%}">
<span
class="item-count"
- >{{thread.answer_count|humanize_counter}}{% if thread.accepted_answer %}{% endif %}</span>
+ >{{thread.answer_count|humanize_counter}}{% if thread.accepted_answer_id %}{% endif %}</span>
<div>
{% trans cnt=thread.answer_count %}answer{% pluralize %}answers{% endtrans %}
</div>
@@ -40,7 +40,6 @@
{% trans cnt=question.score %}vote{% pluralize %}votes{% endtrans %}
</div>
</div>
-
<div style="clear:both"></div>
<div class="userinfo">
<span class="relativetime" title="{{thread.last_activity_at}}">{{ thread.last_activity_at|diff_date }}</span>
@@ -52,7 +51,7 @@
{% endif %}
</div>
</div>
- <h2><a title="{{question.summary|escape}}" href="{{ thread.get_absolute_url() }}">{{thread.get_title()|escape}}</a></h2>
+ <h2><a title="{{question.summary|escape}}" href="{{ question.get_absolute_url() }}">{{thread.get_title(question)|escape}}</a></h2>
{{ tag_list_widget(thread.get_tag_names(), url_params=query_string) }}
</div>