python - django minimize frequent database load -


i have question generalized , applied other problems, , explore possibilities i've got in django.

let's have classical ecommerce scenario. it's relationships , basic field definitions

class basket:   lines (manytomanyfield basketline model)  class basketline:   product_option (foreignkey productoption model)   quantity (integerfield)  class productoption:   option_name (charfield)   product (foreignkey product model)   price (decimalfield)  class product:   name (charfield) 

in addition have basket view accepts basket line modifications (like increment / decrement quantities, delete lines). in view i've noticed pattern in each time try perform modifications each time

1) query user basket
2) target line modified (using basket.lines.filter)
3) update target line modified (line.save())

with individual queries (using django orm). each operation may end retrieving productoption entry check available quantities, , go deep retrieve product entry handle prices.

in given situation best options leverage db querying , distribute load through resources (more or less) evenly, cache user basket, or cache related model data (for short time), because think , believe queries problem scaling basket app. options think of are

1) caching properties of basket (to minimize frequency of retrieval ops)
2) merge many queries possible 1 big query, know minimizes connections , db load
3) cache queries itself, think in changing environment, don't need cached version of basket, while may changed, it's getting hard invalidate cache in right way

so, cut short, prefer hear practical solutions problem (if is) , give me advises in field.

thank much!


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -