基于游标分页数据
Pagination is a technique for breaking large record sets into smaller portions called pages. As a developer, you should be familiar with implementing pagination, but implementing pagination for real time data can become tricky even for experienced developers. In this tutorial, we are going to discuss the practical use cases and solutions for real time data pagination and cursor based pagination.
分页是一种将大型记录集分解为称为页面的较小部分的技术。 作为开发人员,您应该熟悉实现分页,但是即使对于有经验的开发人员,对实时数据实现分页也会变得棘手。 在本教程中,我们将讨论实时数据分页和基于光标的分页的实际用例和解决方案。
识别实时数据分页中的问题 (Identifying Issues in Real Time Data Pagination)
Wikipedia defines real time data as information delivered immediately after collection. There is no delay in the timeliness of the information provided. In such applications, it’s difficult to provide accurate paginated data due to the frequent updates. Let’s take a look at the issues with standard pagination when managing real time data.
维基百科将实时数据定义为收集后立即传递的信息。 所提供信息的及时性没有延迟。 在此类应用程序中,由于频繁更新,因此很难提供准确的分页数据。 让我们看一下管理实时数据时标准分页的问题。
Assumes the data is static and doesn’t change frequently – In default pagination, a retrieved record set is split into a number of pages. As data is not frequently changed, users feel like the pagination is working accurately, but results of the pagination become inaccurate when adding new data or removing existing data.
假设数据是静态的并且不经常更改 –在默认的分页中,检索到的记录集被分为多个页面。 由于数据不经常更改,因此用户感觉分页工作正常,但是在添加新数据或删除现有数据时分页结果变得不准确。
Pagination only considers record count, instead of each individual record – Records are broken into pages using the total record count and paginated normally. It doesn’t consider whether each record falls into the right page on pagination. This can lead to a redundant display of records.
分页仅考虑记录数,而不考虑每个单独的记录 –使用总记录数将记录分为几页,并按正常分页。 它不考虑每条记录是否在分页中都落入正确的页面。 这可能导致记录的冗余显示。
Considering these points, it’s difficult to use to default pagination techniques to handle real time data. Let’s try to identify the issues using a practical scenario.
考虑到这些要点,很难使用默认的分页技术来处理实时数据。 让我们尝试使用实际方案来确定问题。
Assume that we have 20 records initially and we using 10 as the limit to break the records into pages. The following image shows how records are broken into pages.
假设我们最初有20条记录,并且使用10条限制将记录分成页面。 下图显示了如何将记录分为页面。
![title Initial Results](https://i-blog.csdnimg.cn/blog_migrate/732be2db80580c36f441e9a031bc9a37.webp?x-image-process=image/format,png)
Now assume that the result set is updated by five new records while we are on the first page. The following image shows the current scenario.
现在,假设我们在首页上时,结果集由五个新记录更新。 下图显示了当前方案。
![title Results After Adding New Data](https://i-blog.csdnimg.cn/blog_migrate/9623d1afd7f4d5c84b75b4ae59840d69.webp?x-image-process=image/format,png)
Now we navigate to the second page. Based on our first image, it should retrieve the records from 1-10. However, records with numbers 15-6 will be retrieved. You can clearly see that record numbers 15-11 are displayed in both the first page as well as the second page.
现在,我们导航到第二页。 根据我们的第一张图片,它应该从1-10检索记录。 但是,将检索编号为15-6的记录。 您可以清楚地看到记录号15-11在第一页和第二页中都显示。
实时数据分页的实际用例 (Practical Use Cases of Real Time Data Pagination)
As we all know, reinventing the wheel is not something a developer should do. We should look at the existing pagination techniques of sites that solved these issues before thinking about building our own. Many social networking sites such as Twitter and Facebook provide real time data in their user profiles. In this section, we will be looking at the practical use cases of real time data pagination using some of the most popular sites.
众所周知,重塑车轮并不是开发人员应该做的事情。 在考虑构建自己的站点之前,我们应该查看解决这些问题的站点的现有分页技术。 Twitter和Facebook等许多社交网站在其用户配置文件中提供实时数据。 在本节中,我们将研究使用一些最受欢迎的站点进行实时数据分页的实际用