Quantcast
Channel: User JohnP - Stack Overflow
Viewing all articles
Browse latest Browse all 37

Paginating data by last active when rows constantly change

$
0
0

I'm looking for pagination approaches to be used on data that is constantly changing (around 1 - 3 updates per minute).

I have a conversation list with the following structure

conversation : id, user_id, last_message, last_active

The most active conversations change 1 to 3 times per minute and so the last_active column is updated whenever a change is registered. A user can have 100+ conversations.

The problem I have is paginating the data when the last_active value is changing.

If the data is static, you can simply do the pagination with a 'ORDER BY DESC last_active LIMIT n, 15' query on MySQL. But because last_active is constantly changing, the ordering of items can change and so just never show up on the list (or show up multiple times).

For example, if the limit was 3 per page and my data looked like this :

{id : 1, last_active : 10:14:41} {id : 2, last_active : 10:14:31}{id : 3, last_active : 10:13:55}[Page - 1]{id : 4, last_active : 10:13:30}{id : 5, last_active : 10:12:06}{id : 6, last_active : 10:11:10}[Page - 2]{id : 7, last_active : 10:10:20}{id : 8, last_active : 10:10:06}{id : 9, last_active : 10:09:22}[Page - 3]

Now, when the user is on the second page, if an update is carried out to id = 7, it is pushed to the top of the query by the ORDER BY clause, and it never shows up on page 3.

What's the best way to organize this so that I can paginate this data without losing rows or duplicating them?


Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>