K
K
Kirill Gorlov2018-04-26 11:46:27
Web development
Kirill Gorlov, 2018-04-26 11:46:27

How to organize uploading records?

I will not go into implementation details, since I am interested in the algorithm for obtaining records.

Imagine that in the database we have 100 records, on the first page we get the first 10 records.
We start scrolling down the page, press the show more button, load 10 more records.

Everything is fine in this case, until we have the moment of adding records to the database while we were browsing the first 10.

So, here we got the first 10 records [1,2,3,4,5,6,7,8,9,10]
, scrolling down, during this time a couple of records were added to the database [-1,0]
when we received the 2nd page 10 records, we will receive [9,10,11,12,13,14,15,16,17,18]records in the response
, duplicates are obtained, and at the same time the first two ( [-1,0]) will not be displayed above, since we requested the 2nd page.

It immediately comes to mind to check the array for duplicates, for example, by record IDs.
Okay, but what if 100 records got into the database in 1 second?
We will get the 2nd page [-90, -89, -88, -87, -86, -85, -8, -83, -82, -81]and, having reached 0 again, we will again get a double [1,2,3,4,5,6,7,8,9,10]

. How can we deal with this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Simonov, 2018-04-26
@Chetson

Usually they make a temporary label when they started scrolling through the tape, and make a selection from the database using this label. That is, we made the first request at 16:00, which means we need to show the first 10 records from the tape, then someone adds something at 16:01, and at 16:02 we click on the button to show 10 more. After that the sample will go, so that we select the second batch of data that was before 16:00. And so the record that was at 16:01 will not fall and will not break anything. And on the interface we can show (as in VK for example) that there is a new entry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question