In reverse time order paging query, new data is inserted into the db during page turning, resulting in duplicate data being returned. Is there any good solution to this? thank you all

WBOY
Release: 2016-08-04 09:22:14
Original
1909 people have browsed it

Paging query in reverse time order, new data is inserted into the db during page turning, resulting in duplicate data. Is there any good solution to this? Thank you everyone

Reply content:

Paging query in reverse time order, new data is inserted into the db during page turning, resulting in duplicate data. Is there any good solution to this? Thank you everyone

Is this the data duplication you are talking about? During the page turning process, someone inserted a piece of data, and then the last piece of data on the first page was assigned to the second page again and became the first output piece on the second page. , this piece of data appears twice?
If that’s what you mean, I suggest you do paging on the client. When querying, add a time point. Data that is less than the time when you click the query button will be found, and then perform paging on the client. In this way, new data will not be retrieved. It will affect paging because the new data is not retrieved at all. Since this is a time flashback, even if there is new data, it will not be seen and there will be no data omission. When the data is loaded again and the data is fetched, the new data will be queried.

I just dealt with a similar problem on the mobile side some time ago. Let me talk about the ideas on the mobile side:
1. First, it is divided into pulling down (getting the latest data) and sliding up (getting the previous data).
2. Secondly, swiping up every time to get it. In the previous data, I would pass an id and use this id as a condition to obtain the data. If you are in reverse order of time, you can basically assume that the id is also in reverse order. The id just passed should be the smallest id in the previously obtained data. Except for the first time, every time you obtain data in the future, it will be data smaller than this id
3, first When getting data for the first time, because there is no ID, just get the first data in order.

Hope this helps with your question!

Sorry is the best language in the world.
My answer is based on nodejs.
But it doesn’t matter, just understand the idea.

-------Original answer------

When I looked at the API of coding.net, I found that it has two more methods.
The syntax is based on mongoose
One is through paging and pagify. For example, if there are 20 pages, Model.find(query).skip(page*20 - 20).limit(20).
The second is to load more after, specifically after. I have never developed anything like this, and I am not sure if mongodb has such an attribute after. However, it is relatively simple to rely on things in a sort, Model.find(query).sort('-time').where({time:{$gt:TIME}}).limit(20)

Not sure if there is

It would be better if mongodb has something similar to after. (note time may crash, but id will not)
Model.find(query).sort('-time').after({id:ID}).limit(20)

Added more request APIs in coding.net

GET https://coding.net/api/activities/projects_last?last_id=14959187

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!