adzialocha / hoffnung3000

Platform for decentralized, anonymized, self-curated festivals
https://hoffnung3000.de
GNU Affero General Public License v3.0
36 stars 8 forks source link

Events from the next page are not ordered correctly #103

Closed adzialocha closed 2 years ago

adzialocha commented 4 years ago

Clicking on the "Load More" button in the paginated calendar view results in loading new events which are not ordered correctly by time. Example:

Calendar displays:

* Event 1 12.04.20
* Event 2 14.04.20
* Event 3 23.04.20

A click on "Load more" results in:

* Event 1 12.04.20
* Event 2 14.04.20
* Event 3 23.04.20
* Event 4 20.04.20 (not in order!)
sandreae commented 4 years ago

So I think this is a Sequelize bug, they seem to have a bunch of issues when findAndCountAll is involved with, limits, counts, orders and offsets. I found one suggested solution which is to add a {subQuery: false} param to the findAndCountAll request.

https://github.com/adzialocha/hoffnung3000/blob/f1cb5ddf3b333449e03aa05e1eb69873cc91a887/server/controllers/event.js#L463-L472

the above would become this:

return Event.findAndCountAll({
      distinct: true,
      include: req.user.isVisitor ? includeForVisitors : include,
      limit,
      offset,
      order: [
        [EventHasManySlots, 'from', 'ASC'],
      ],
      where: req.user.isVisitor ? { isPublic: true } : {},
      subQuery:false,
    })

I tried this locally and it seemed to work, but then when I pushed the fix to my antiuniversity branch a different problem came up where only two pages of events were being fetched but not the rest. They were in the correct order though....

Might be worth trying this fix, or I suggest just disabling pagination for the calendar page while we figure out the proper fix.