Last posts didn't show last 5 posts

Bug #1635676 reported by kaputtnik on 2016-10-21
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Widelands Website

Bug Description

Under sum circumstances the Last Posts box does not show the last 5 posts.

The for-loop in pybb/templatetags.pybb_last_posts() is the culprit here.

The for-loop gathers only the last post in each topic. This result in less shown 'Last Posts': Extreme example: If the 25 'last_posts' are made in one topic, the 'Last Post' box shows only one entry (the last post in this topic).

I have increased the limit for last_posts to 45 now.

Another solution would be to show all last posts, independent of the topic. We may need additional UI elements then, like shown here


Related branches

GunChleoc (gunchleoc) wrote :

I don't know how the filtering in Django works, but normally I would ask the database to select the last 5 posts that meet the filter condition. SQL looks something like

Select <fields> from table where (<condition>) limit 5

Can we coax Django into doing something like that?

kaputtnik (franku) wrote :

Yes, of course we could just show the last 5 posts independent from the topic. So if one topic contains all the last 5 posts only those posts of this topic where shown.

I guess the idea for the current implementation was to have some more topics shown. Because not everyone is interested in each topic.

Or did i misunderstood you?

GunChleoc (gunchleoc) wrote :

No, that's not what I meant at all. At the moment, it seems that you fetch the last 5 topics from the database and then filter them afterwards, leaving us with less topics. If the filtering was happening with the database call itself, we would get 5 viable topics from the database. So, we wouldn't need to fetch a large amount to make sure that at least 5 will remain after the filtering.

kaputtnik (franku) wrote :

No, currently the last 45 posts are fetched (before my change it were 25):

last_posts = Post.objects.filter(hidden=False).order_by('-created').select_related()[:45]

Then the code looks to which topic one of this posts belongs to, put this topic in a check list, add the post to an answers list. If another topic of a post (of the 45 last posts) is in the check list (a topic was already found), omit it.

This loop runs until 5 (different) topics are found or the list of 45 posts ends, and the gathered posts are returned.

Maybe there is another way doing this by filtering the topics by the 'updated' property, but since this works i didn't dive into it.

GunChleoc (gunchleoc) wrote :

An idea for the future then - it would make things more efficient.

kaputtnik (franku) on 2017-01-19
Changed in widelands-website:
status: New → Triaged
importance: Undecided → Low
kaputtnik (franku) wrote :

Since we have currently only 3 latest post in the box, i have started to work on this with an other idea:

- The Latest posts box get an additional link
- The link shows a new page containing all posts from the last 30 days, sorted by posts date (newest first) and grouped by topics name

I want to hear your opinion for this, and may add a form to get the days editable by the user.

Changed in widelands-website:
assignee: nobody → kaputtnik (franku)
status: Triaged → In Progress
kaputtnik (franku) wrote :
kaputtnik (franku) on 2019-03-21
Changed in widelands-website:
status: In Progress → Fix Released
assignee: kaputtnik (franku) → nobody
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers