A
A
Andrey Shubin2014-12-18 17:37:56
MySQL
Andrey Shubin, 2014-12-18 17:37:56

How to reduce the number of queries to the database?

Hello!

I use Python + Flask + SQL-Alchemy to create sites, and quite often there is a situation when the layout (page template, usually a header + footer) contains a menu, customer reviews, and so on.
All these things are loaded from the database, respectively, each time you open any of the pages, requests are made to load reviews, comments, menus and other things.

Tell me how you can reduce the number of requests? Merge into one, cache, maybe something else? By what means can this be achieved?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
Boris Benkovsky, 2014-12-18
@idegree

They answered their own question. Use Cash. Google, because there is a sea of ​​information, as well as approaches. If you do not have Plain Python (and judging by the question, no), then you can find something ready for your framework.

O
Oxoron, 2014-12-18
@Oxoron

There is also Ajax, which helps to update only part of the page.
When you open a new one, there are still cookies, you can store some of the information there.
When updating, you can send information to the server about the time the page was created timeCreation, return only comments written after timeCreation.

D
Dmitry Shnyrev, 2014-12-22
@dmnBrest

Ajax is bad for SEO. If you want to make a popular site that search engines will notice, then no Ajax!!! Cash is a great option. You can write it yourself if you don’t want to dig into ready-made solutions. Take for example Redis and add information there (ready-made pieces of rendered templates). When loading the page, take information from Redis, if it is not there or it is "rotten", then take it from the database and simultaneously update it in Redis.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question