PHPBB3-15100 - "last_post_id" meaning is overloaded

Discuss requests for comments/changes posted in the Issue Tracker for the development of phpBB. Current releases are 3.2/Rhea and 3.3/Proteus.
Post Reply
User avatar
javiexin
Registered User
Posts: 90
Joined: Thu Dec 22, 2011 10:04 am

PHPBB3-15100 - "last_post_id" meaning is overloaded

Post by javiexin »

Hello,

I have found what seems to me an issue with overloading the use of last_post_id (and first_post_id) with two different meanings.

In fact, last_post_id means, sometimes, highest post id, and other times, post id of the latest post time. However, it is always calculated as highest post id, assuming that the highest post id corresponds to the id of the latest post. This last assumption is FALSE under certain circumstances, and hence, the output is not what is expected. These are rare cases though, but "semantically", the two concepts are incorrectly intermixed in my view.

An example that demonstrates what I mean: we have the following in the posts table in the DB (simplified for clarity):

Code: Select all

Forum		Topic		Post		Time
1		1		1		1
1		1		2		2
1		1		3		3
1		2		4		4
1		2		5		5
In this context, last_post_id would be 5 for forum 1, and for topic 1 and 2 would be 3 and 5 respectively.
Similarly, for first_post_id, forum 1 would have 1, while topic 1 and 2 would have 1 and 4 respectively.
Note that this is true both with the meaning of "lowest/highest" and "earliest/latest".

Now, we duplicate topic 1, delete post 1, and we get the following posts table:

Code: Select all

Forum		Topic		Post		Time
1		1		2		2
1		1		3		3
1		2		4		4
1		2		5		5
1		3		6		1
1		3		7		2
1		3		8		3
Here is the issue. Now, last_post_id would be 8 for forum 1, as "highest", but however, it should be 5 with the meaning of "latest".
And the issue also manifests for first_post_id: now it would be 2 (lowest) while the "earliest" would have to be 6.

In my opinion, it should be clear what "semantics" we want to apply to "last_post_id" in each situation, and act accordingly.
First and last are used with the meaning of lowest and highest, for example, when resynchronizing counters.
And are intented to be used with the meaning of earliest and latest when applied to topics and forums.

Related to this, but totally different problem, is the following: if you have an "unapproved" post, and before it gets approved, there are other posts in the same topic (that might not need approval), if someone visits the topic, the "unapproved" post will show as read when approved, and it should not. Besides, it is listed in "publication" order, but it should probably be listed in "approval" order (to be consistent to when this post was VISIBLE to everyone with the right permissions).

These applies both to 3.1 and 3.2; I have not tested master, but I guess it would be the same. What do you think? Should this be fixed, or leave it as is, given that the inconsistencies are corner cases? By the way, these "corner cases" are more frequent when you use the "MCP Change Post Time" extension, as you are manipulating the timeline (but not the post ids), that is why I got to this... Anyhow, the inconsistencies are there without any extension, so clearly a core "bug" or "feature"...

Before you ask: this change should not result in (almost) any performance impact, as the posts table is indexed both on post_id and post_time.
Regards,
-javiexin
Last edited by javiexin on Wed Feb 22, 2017 7:39 pm, edited 1 time in total.

User avatar
javiexin
Registered User
Posts: 90
Joined: Thu Dec 22, 2011 10:04 am

Re: "last_post_id" meaning is overloaded

Post by javiexin »

Sorry to bump this topic: I am getting complains from people using the "Change Post Time" extension, as the time is not honored in the forum (and topic) first and last post ids. This is NOT an extension issue, it is a core issue, as I showed above. Any opinions? Should we try to solve it? Or leave it alone?
-javiexin

User avatar
3Di
Registered User
Posts: 951
Joined: Tue Nov 01, 2005 9:50 pm
Location: Milano 🇮🇹 Frankfurt 🇩🇪
Contact:

Re: "last_post_id" meaning is overloaded

Post by 3Di »

FWIW Javier, referring to the first issue you above posted. For an ext (validated) of mine I am using this method:

If same total posts and same exact post time then the post ID rules

an excerpt of the main query that assigns the top poster of the month

Code: Select all

				GROUP BY u.user_id
				ORDER BY total_posts DESC, p.post_time DESC, p.post_id DESC';
I couldn't imagine any other alternative. There are rare occasions where it could happens but it could.
it should be clear what "semantics" we want to apply to "last_post_id" in each situation, and act accordingly.
Yes, agreed. In my infinite lurking at the tracker I recall I have found similar discussions/issues. Since ages.
About "semantics" to apply to this or that, I recall there is at least one discussion, quite new (extensions writer forum) , that relates to another part of the code/events as well. Mainly speaking about code "consistency", so to say.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades

User avatar
Jacob
Registered User
Posts: 102
Joined: Wed Jan 04, 2012 1:41 pm

Re: "last_post_id" meaning is overloaded

Post by Jacob »

Interesting.

The behaviour should be changed, in my opinion, to use "earliest" and "latest" ("post time").

User avatar
javiexin
Registered User
Posts: 90
Joined: Thu Dec 22, 2011 10:04 am

Re: "last_post_id" meaning is overloaded

Post by javiexin »

I have created a tracker entry, so that this is not lost: https://tracker.phpbb.com/browse/PHPBB3-15100

Post Reply