discourse/plugins/discourse-post-voting
Régis Hanol 0a2a6b4871
FIX: Redirect over-range topic page URLs instead of 404 (#40224)
Requesting `/t/slug/id?page=N` with a page number beyond the topic's
last valid page raised `Discourse::NotFound` and returned 404. This
produced a long-running stream of "increase in 404 errors" reports in
Google Search Console, because crawlers (and our own
`sitemap_recent.xml`) hold cached page URLs that become stale when a
topic shrinks — most often after deleted posts or topic splits.

The 404 also masked a latent bug for staff: the original check compared
the requested page against `topic.posts_count`, a cached column that
excludes whispers and ignores active filters (`username_filters`,
`replies_to_post_number`, etc.). A staff user navigating to `?page=N`
covering whisper posts could be 404'd even though the page contained
content they were entitled to see.

Replace the 404 with a 301 redirect to the last valid page (or the
unparameterized topic URL if the topic fits in one page), using
`@topic_view.filtered_posts.count` — the count of posts visible to the
current viewer — so the math respects whispers, deletions visible to
staff, and active filters. The COUNT query is gated behind `page > 1` so
the common case (no `?page=` param) pays nothing extra.

Negative pages still raise 404; only the over-range case becomes a
redirect.

https://meta.discourse.org/t/96337
2026-05-22 18:48:59 +02:00
..
app DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
assets DEV: Consolidate reusable components into ui-kit (#38703) 2026-05-11 18:07:36 -03:00
config I18N: Update translations (#40027) 2026-05-17 19:13:55 +02:00
db/migrate
extensions DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
lib DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
spec FIX: Redirect over-range topic page URLs instead of 404 (#40224) 2026-05-22 18:48:59 +02:00
test/javascripts/acceptance FIX: Update post-voting test selectors to match BEM rename (#39457) 2026-04-22 16:30:38 +02:00
package.json DEV: Add a script for generating external types in discourse-types (#37095) 2026-03-09 20:37:43 +01:00
plugin.rb DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
README.md
tsconfig.json DEV: Add a script for generating external types in discourse-types (#37095) 2026-03-09 20:37:43 +01:00

Discourse Post Voting

Discourse Post Voting allows the creation of topics with votable posts.

image

Please refer to https://meta.discourse.org/t/227808 for more info!

Contributions

Special thanks to Pavilion for building https://github.com/paviliondev/discourse-question-answer which this plugin took inspirations from.