Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3701

Paginating data after processing of almost all data

$
0
0

Context:

I have a MongoDB collection that contains data on service providers. I need to filter this data to generate a list of service providers based on specific criteria. The final price for a service is calculated using the following formula:

Final Price = Base Pricing + min(Number of People Availing the Service, Max People Count the Service Provider Can Entertain) * Price Per Person + Extra Person Pricing * Number of Extra People Availing the Service

The number of extra people availing the service is determined by:

Number of Extra People} = max(Total Number of People Availing the Service - Max People Count the Service Provider Can Entertain, 0)

Note: A service provider can serve at most 20% more people than their normal capacity.

Fields in the Collection:

  • City
  • Base Pricing
  • Max People Count the Service Provider Can Entertain
  • Price Per Person
  • Cost Per Extra Person
  • Other relevant counts and prices

Current Approach:

In the Listing API I'm developing, users can pass in the city, budget range (min-max), and the number of people availing the service. My current approach is as follows:

  1. City Filter: Apply a filter to get all service providers in the specified city.
  2. Price Calculation: For each service provider, calculate the final price based on the provided formula only if they can serve the number of people user entered.
  3. Pagination: Return the data in a paginated format according to the user's budget.

However, since I'm processing all the data from the specified city, I'm considering whether I should send all the final data in one go. This approach, however, feels inefficient and possibly not the best solution.

Challenge:

I'm looking for a more efficient and scalable approach that can improve the performance of the Listing API while ensuring that the results are relevant and useful for the end-user.


Viewing all articles
Browse latest Browse all 3701

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>