SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 0a5e9ef0 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Accelerate with prefetch, improve listing

parent ac84de25
No related branches found
No related tags found
No related merge requests found
# Generated by Django 3.2.16 on 2023-01-29 14:03
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('forums', '0011_alter_motion_accepted'),
]
operations = [
migrations.AlterModelOptions(
name='meeting',
options={'ordering': ['-date_until']},
),
]
......@@ -149,6 +149,11 @@ class Meeting(Forum):
)
objects = models.Manager()
class Meta:
ordering = [
"-date_until",
]
def __str__(self):
return "%s, [%s to %s]" % (
self.forum,
......
<li class="d-flex flex-wrap justify-content-between">
<a href="{{ forum.get_absolute_url }}">{{ forum }}</a>
<span class="badge bg-secondary rounded-pill">{% with nr_posts=forum.nr_posts %}{{ nr_posts }} post{{ nr_posts|pluralize }}{% endwith %}</span>
<span class="badge bg-primary rounded-pill">{% with nr_posts=forum.nr_posts %}{{ nr_posts }} post{{ nr_posts|pluralize }}{% endwith %}</span>
{% if forum.child_forums.all|length > 0 %}
<ul class="list-unstyled forumList">
{% for child in forum.child_forums.all %}
......
......@@ -45,7 +45,13 @@
{% endif %}
<span class="d-flex flex-wrap justify-content-between">
<a href="{{ forum.get_absolute_url }}">{{ forum|truncatechars:30 }}</a>
<span class="badge bg-primary rounded-pill">{% with nr_posts=forum.nr_posts %}{{ nr_posts }} post{{ nr_posts|pluralize }}{% endwith %}</span>
{% with nr_posts=forum.nr_posts %}
{% if nr_posts %}
<span class="badge bg-primary rounded-pill">
{{ nr_posts }} post{{ nr_posts|pluralize }}
{% endif %}
{% endwith %}
</span>
</span>
</div>
<div class="card-body">
......@@ -54,7 +60,7 @@
<hr/>
<p>Descendants:</p>
<ul class="list-unstyled forumList">
{% for child in forum.child_forums.all %}
{% for child in forum.child_forums.all reversed %}
{% include 'forums/forum_as_li.html' with forum=child %}
{% endfor %}
</ul>
......@@ -83,12 +89,16 @@
</thead>
<tbody>
{% for forum in object_list %}
<tr>
<td><a href="{{ forum.get_absolute_url }}">{{ forum }}</a></td>
<td>{{ forum.latest_post }}</td>
<td>{{ forum.latest_post.posted_on|date:"Y-m-d" }}</td>
<td><span class="badge bg-primary rounded-pill">{{ forum.nr_posts }}</span></td>
</tr>
{% with formul.latest_post as latest_post %}
{% if latest_post %}
<tr>
<td><a href="{{ forum.get_absolute_url }}">{{ forum }}</a></td>
<td>{{ forum.latest_post }}</td>
<td>{{ forum.latest_post.posted_on|date:"Y-m-d" }}</td>
<td><span class="badge bg-primary rounded-pill">{{ forum.nr_posts }}</span></td>
</tr>
{% endif %}
{% endwith %}
{% empty %}
<tr>
<td>No visible Posts found.</td>
......
......@@ -176,7 +176,10 @@ class ForumListView(LoginRequiredMixin, ListView):
def get_queryset(self):
queryset = get_objects_for_user(
self.request.user, "forums.can_view_forum"
).anchors()
).anchors().select_related("meeting").prefetch_related(
"posts" + "__followup_posts" * 3,
"child_forums__posts" + "__followup_posts" * 7,
)
return queryset
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment