PopulateTools / gobierto

Plataforma de gobierno abierto open source
https://gobierto.es
GNU Affero General Public License v3.0
74 stars 32 forks source link

Prevent deep pagination in events pages (from bots) #4209

Closed ferblape closed 8 months ago

ferblape commented 8 months ago

:v: What does this PR do?

Checking the slow queries I've found many (many many) slow queries caused by a deep pagination in people calendar.

This PR blocks page > 5 in past events page, (i.e https://portalobert.esplugues.cat/agendas/pilar-diaz-i-romero/eventos-pasados?list_view=true). If a use wants to see older events she can use the calendar in the left sidebar to navigate across days.

The reason is the OFFSET parameter, a deep pagination uses a super-high offset, which for Postgres is really hard to process, because it has to bulid the query sorted, and then iterate until the OFFSET.

This is not the final solution, probably we should fix the query and the offset, but for know it leverages a hundreds of slow queries per hour.

furilo commented 8 months ago

It can be a final solution, until some one complains ;)