Skip to main content

How to handle or design review system with pagination? [Resolved]

In typical online review system if any user give review on specific post or others thing, then when that user view that post his review show first. The perfect example of this is Google Play Store. If i give review to any app, than when i go to that app my review show first.

Now i want to implement review system in my app. I implemented it successfully but now I'm little bit confused to showing that to the users. I want to show current user review first if that user give any review to that post as I mentioned before. I can simply do that if I fetch all the data at a time by doing filter for current user but as I'm using pagination and don't getting all the data at a time so I can't do that because theres no guaranty that the current user data will exists in that page.

So the way i think to solve the problem is below:

For first page call I can make two call to database one for to get only current user review data and second to get all review data by paging. Then if current user review data exists I will add this data to the beginning of all data. But there has one problem, as I'm calling current user review data separately still my main call which getting all review data may exist that current user review data. It means current user review data maybe duplicates. So, to prevent duplicates data I can exclude current user data from all data call but that will put an extra load to the sever as it will check every data and then will skip current user data if exits.

So I'm looking for an efficient way to show users review by doing pagination, where first review will be current user review if it exists. How can I do that?


Question Credit: Rhidoy
Question Reference
Asked July 21, 2019
Posted Under: Programming
22 views
1 Answers

Don't do premature optimization. Filtering reviews based on the ID of a user takes microseconds: I'm pretty sure the bottleneck in your app is at somewhere else.

Query the review of the current user, and show it immediately, as the user may be interested to know as soon as possible that he already reviewed the entity. Then, do an AJAX request to get the first batch of reviews. No need to be concerned by the current user at this point: just flush the whole batch to the client.

On client side, filter out the reviews to exclude a review by the current user. Show the results.

Why on client side? Mostly because this will allow you to cache data aggressively. Whenever two users access reviews of the same set entity, they get the exact same result; it's up to the client to customize how this result should be displayed based on the current user.


credit: Arseni Mourzenko
Answered July 21, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA