Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archive pages limit uncovers interesting breakage #693

Closed
th-h opened this issue Apr 11, 2020 · 0 comments
Closed

Archive pages limit uncovers interesting breakage #693

th-h opened this issue Apr 11, 2020 · 0 comments
Labels
backport needed Fix that has to be backported to older release branches. bugs discuss
Milestone

Comments

@th-h
Copy link
Member

th-h commented Apr 11, 2020

Since merging of #665 - which was backported and released with 2.3.3 - serendipity_plugin_history breaks with a SQL error for all archive pages but the first:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-10, 10' at line 38

This is due to the fact that serendipity_fetchEntries() in include/functions_entries.inc.php is not just called to display entries on pages, but also to get a list of entries for many other use cases so the calculation of $totalEntries may not always return the result that you expected. Please bear with me, it's a bit of convoluted.

  • In this case, we're showing archive page 2 of many. On this page, serendipity_plugin_history tries to show up to 10 older entries that have been posted about a year ago (let's say at least 360, but not more than 370 days ago). It does that by calling serendipity_fetchEntries() with a range and a limit of 10. But today, there are no historic entries to show.

  • The code in serendipity_fetchEntries() will construct $serendipity['fullCountQuery'] as always with all constraints from the serendipity_fetchEntries() call and pass it to serendipity_getTotalEntries(); the result will be 0 this time, so $totalEntries will be 0, too. That means we have zero archive pages ($totalPages) , too. The archive page limiting code will set $serendipity['GET']['page'] to zero accordingly.

  • And further on, the paginating code kicks in and constructs the LIMIT query. It does that by setting the offset to the number of entries that have already been displayed by subtracting 1 from the current page and multiplying that with the limit of entries to show, i.e. on page 2 when showing 10 entries on every page, it gives (2-1)*10 = 10. But we have forced $serendipity['GET']['page'] to zero, so now it is (0-1)*10 = -10 which is invalid.

We could roll back that change, but I think we don't consider the possibility that we don't use $limit to paginate here, i.e. that serendipity_fetchEntries() is called for another purpose than displaying an archive page, at all. It would also be wrong to display the "historic" entries in reverse order if $serendipity['archiveSortStable']) ist set to true.

So I think the archive limiting code is not wrong per se but has uncovered a design problem. That's why I think we should keep that code to uncover other problems like this.

We could add another parameter to serendipity_fetchEntries() to check if we need to paginate, but the parameter list already is impressingly long. So I'll fix the problem in the calling code; we'll have to keep that in mind for other places where that will creep up, so I'll let this issue open a bit for discussion.

@th-h th-h added bugs discuss backport needed Fix that has to be backported to older release branches. labels Apr 11, 2020
@th-h th-h added this to the 2.3.5 milestone Apr 11, 2020
th-h added a commit to th-h/Serendipity that referenced this issue Apr 11, 2020
Since merging s9y#665 `serendipity_plugin_history`
breaks with a SQL error message on every archive
page but the first one; see s9y#693 for reason
and context.

Unset `$serendipity['GET']['page']` before
calling `serendipity_fetchEntries(`)` (and
reset afterwards) to fix that. That's the
correct way, I think, as
`serendipity_fetchEntries()` is not called
in page context here.

Signed-off-by: Thomas Hochstein <thh@inter.net>
th-h added a commit to th-h/Serendipity that referenced this issue Apr 11, 2020
Since merging s9y#665 `serendipity_plugin_history`
breaks with a SQL error message on every archive
page but the first one; see s9y#693 for reason
and context.

Unset `$serendipity['GET']['page']` before
calling `serendipity_fetchEntries(`)` (and
reset afterwards) to fix that. That's the
correct way, I think, as
`serendipity_fetchEntries()` is not called
in page context here.

Signed-off-by: Thomas Hochstein <thh@inter.net>
th-h added a commit to th-h/Serendipity that referenced this issue Apr 11, 2020
See s9y#693 for context. That should at least
avoid SQL errors.

Signed-off-by: Thomas Hochstein <thh@inter.net>
@th-h th-h closed this as completed in 9b65e71 Apr 11, 2020
th-h added a commit to th-h/Serendipity that referenced this issue Apr 11, 2020
Since merging s9y#665 `serendipity_plugin_history`
breaks with a SQL error message on every archive
page but the first one; see s9y#693 for reason
and context.

Unset `$serendipity['GET']['page']` before
calling `serendipity_fetchEntries()` (and
reset afterwards) to fix that. That's the
correct way, I think, as
`serendipity_fetchEntries()` is not called
in page context here.

Add a note to serendipity_fetchEntries()
about the problem with page context.

Also don't fallback to last page if
$totalPages < 1 in serendipity_fetchEntries()
That should at least avoid SQL errors.

Signed-off-by: Thomas Hochstein <thh@inter.net>
th-h added a commit to th-h/Serendipity that referenced this issue Apr 20, 2020
Since merging s9y#665 `serendipity_plugin_history`
breaks with a SQL error message on every archive
page but the first one; see s9y#693 for reason
and context.

Unset `$serendipity['GET']['page']` before
calling `serendipity_fetchEntries()` (and
reset afterwards) to fix that. That's the
correct way, I think, as
`serendipity_fetchEntries()` is not called
in page context here.

Add a note to serendipity_fetchEntries()
about the problem with page context.

Also don't fallback to last page if
$totalPages < 1 in serendipity_fetchEntries()
That should at least avoid SQL errors.

Signed-off-by: Thomas Hochstein <thh@inter.net>
th-h added a commit to th-h/Serendipity that referenced this issue Apr 20, 2020
Since merging s9y#665 `serendipity_plugin_history`
breaks with a SQL error message on every archive
page but the first one; see s9y#693 for reason
and context.

Unset `$serendipity['GET']['page']` before
calling `serendipity_fetchEntries()` (and
reset afterwards) to fix that. That's the
correct way, I think, as
`serendipity_fetchEntries()` is not called
in page context here.

Add a note to serendipity_fetchEntries()
about the problem with page context.

Also don't fallback to last page if
$totalPages < 1 in serendipity_fetchEntries()
That should at least avoid SQL errors.

Signed-off-by: Thomas Hochstein <thh@inter.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport needed Fix that has to be backported to older release branches. bugs discuss
Projects
None yet
Development

No branches or pull requests

1 participant