I program a site in PHP / MySQL that receives search results for products through the API from an external site. This site will also have its own products, and site owners want search results to be related.
If someone is looking for a VIDEO ordered by date, then the results should be in order, regardless of the source from which it came.
eg.
July 31 - Video A - our database
July 30 - Video B - via API
July 29 - Video C - via API
July 28 - Video D - our database
...
The problem I am facing is finding a way to do this efficiently, especially regarding viewing multiple pages of results. If someone clicks on the second page of results, I need to find out the last element on the first page of results (and the last element from the API), and then get only the elements from the API, starting from the last API element in question on the previous page, and then do the same most for the results of our database and combine them again again.
To avoid this complex algorithm, another idea I had was to limit the results to a large number - for example, 500 results and immediately grab them and arrange them. Then, if the user goes to several pages, I do not need to intercept all the data.
- ?