miguelgrinberg / microblog-api

A modern (as of 2024) Flask API back end.
MIT License
365 stars 100 forks source link

Microsecond precision for pagination #25

Closed Christoph-ModelMe closed 2 months ago

Christoph-ModelMe commented 1 year ago

Hi, I noticed problems with my pagination. After I digged into it, I noticed that for my app the pagination does not work if the posts were all created in the same second, even though they differ in the microseconds and the microseconds are correctly stored in the database.

Is this maybe a marshmallow bug or in the code or on my end?

miguelgrinberg commented 1 year ago

You haven't described what the problem is, you just said there is a problem. Without details I have no way to provide advice. Does my application in this repo suffer from the same issues? If not I would suggest you review your paginated query.

Christoph-ModelMe commented 1 year ago

oh yes sorry... So I could reproduce it with this repo. This is what I did:

BUT:

miguelgrinberg commented 1 year ago

This could be a floating point precision issue. I would suggest that if you need high accuracy at the microsecond level you use an integer not a datetime, which would write the seconds as a float. The integer could be a UNIX timestamp multiplied by 10^6, so that you store it in microseconds instead of seconds.