Home  >  Q&A  >  body text

java - 如何解决按登录时间分页加载数据会有重复的问题?

场景是这样的:安卓客户端要按登录时间在首页显示用户列表,服务端提供数据,每次下拉请求,相当于是从服务端请求加载下一页的的数据,但是这样会有一个问题,假如第一页服务端给了客户端最新的数据,但是在加载第二页之前,又有几个新的用户登录了进来,这样这些新用户就是最新登录的,所以在第二页的时候就会有一些第一页的用户,请教给位大神怎么解决这个问题?

PHP中文网PHP中文网2726 days ago912

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-17 13:27:20

    Several options:

    1. Client-side deduplication, advantage: simple to implement. Disadvantages: Data is inaccurate.

    2. (Recommended) Sort by time. When the client obtains the next page of data, it returns the login time of the last data. When querying the database, select * from table where login time < the last data Login time order by login time.

    3. Record a timestamp for each client. Update this timestamp when getting the first page. When querying the next page, select * from table where login time < timestamp order by login time limit current Page

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:27:20

    If the order of users remains unchanged, you can record the last user displayed each time. After getting the next page from the server, search first. If there is the last user before, skip him and the previous users. , in order to avoid not having enough users, you may need to load a few more at a time according to the actual situation. If a user who was supposed to be on the second page moves to the front because he logged in again, that should be fine, and generally no one will notice.

    reply
    0
  • Cancelreply