Reputation: 6684
Let's say I have a scenario where I have a Service that is responsible for retrieving the price of a single product given the ID and another Service that gives me the current stock position of it.
It's okay when I'm looking only at one product, but what about a list page where I have 60 products? What should I do in this case? Call the service product by product to retrieve it's current price and stock position?
I think this would be extremely slow and cost a lot of resources. But what could I do to make it look good and at the same time have performance?
Currently we have these information in the database in a column next to the product. These price and stock columns are updated by a sql service that updates it when is necessary so when I need to grab the value for a lot of products at the same time I just need to select two columns more. It's really fast, but right now we have some more systems in need of this information and I would like to transform all these stuff in a service.
Thanks a lot!
Upvotes: 0
Views: 409
Reputation: 46410
Can your service method take an array of IDs? And return an array of values? That way if you want one record your array only has 1 item, if you want more, you just populate the array with multiple values?
Upvotes: 0
Reputation: 755043
Well, you could always have multiple service methods:
This way, you could keep your current users happy, and also do something to make batch requests work more efficiently.
Upvotes: 2