Skeletor
Skeletor

Reputation: 3403

Should I use a accessor that calculates the price or a separate field for price calculation?

Sorry because of the title, it may not be that explanatory. Well I have products where the price consists of a multiplication using a currency and the product's base (price) value. I think I have two options to create or access this price result.

I guess the first approach needs some extra process for the scheduled calculations (depending on the frequency) which could be a drawback. The latter would only make the calculation when the product is called. But don't know what happens when I call a lot of products. Well for listing I can use pagination but for other product processes I would need large amounts of prıducts. I am not quite sure and haven't that much experience and knowledge about accessors. Any thoughts would be appreciated.

Upvotes: 0

Views: 72

Answers (1)

Spholt
Spholt

Reputation: 4012

Unless we are talking about thousands and thousands of products being returned, an accessor should do the job well enough.

I would suggest doing this as the first approach and then checking to see what impact it has upon performance using debug tools. If it is an acceptable change in performance, stick with it.

Pre-calculating the prices and storing them in either a database or cache seems like a lot of work if the performacne increase would be negligible.

Upvotes: 1

Related Questions