toptal / chewy

High-level Elasticsearch Ruby framework based on the official elasticsearch-ruby client
MIT License
1.88k stars 366 forks source link

Fix incorrect pagination in journaling #848

Closed konalegi closed 2 years ago

konalegi commented 2 years ago

This PR fixes two bugs:

1. Entry (id: 1, created_at: '12:01:00')
2. Entry (id: 3, created_at: '12:04:00')
3. Entry (id: 2, created_at: '12:03:00')
4. Entry (id: 4, created_at: '12:05:00')

and the current algorithm step by step

  1. fetch 2 items older than 12:00:00, as a result, entries with ids 1, 3 will be fetched (src)
  2. calculate the latest in the batch (src), latest created_at will be 12:04:00
  3. fetch 2 items older than12:04:00, as a result, we are going have entry with id: 4 only
  4. Entry with 2 will be lost

This bug fix is simple, fetch all entries ordered by created_at


Before submitting the PR make sure the following are checked: