H
H
hunter_outlaw2016-07-02 20:27:34
MySQL
hunter_outlaw, 2016-07-02 20:27:34

How to make a selection with counters?

Hello
There is a catalog of goods. The counters of comments, likes and views are placed in a separate table. If you make a normal selection of goods, then the request is cached using the built-in caching mechanism and, accordingly, subsequent selection results for the same request are taken from the cache, which significantly speeds up the work.
It is necessary to implement the ability to sort by the number of views and likes, but to implement this, it is necessary to join both tables (products and counters) using JOIN LEFT. But such requests are already less efficient, since with each update of the counter, the result of the request is removed from the cache, which makes the request almost 20 times slower.
How to correctly implement a system of counters and sorting, so that it does not negatively affect performance?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2016-07-03
@hunter_outlaw

Sobsno what's the problem? Your server hangs, there are not enough connections to the database? Users are jacked up by a rapid jack and the server does not have time to return uncached requests?
If not, what are the problems? So it is and so it should be, selection from tables with actual data will always come from the database directly, if the join does not include 4 tables with over 10 million records - everything will work quickly, well, if the structure is correct. And if not, see how to optimize the databases, the cache is generally nothing here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question