📜 ⬆️ ⬇️

How to not do sites on NetCat

This article will be of interest primarily to those who use NetCat in creating websites. However, the rest of the developers of this information may be interesting. Because in many respects this also applies to other systems.

So, recently I had to figure out why the site developed on NetCat began to work slowly. In the process, it turned out that ~ 150 queries to the database were performed to form the main page!

At first I could not believe my eyes, and then the ooh was horrified.

After some manipulations, we managed to remove about 100 extra requests.
')
I want to talk about some of the findings and caution some developers.

  1. It is not necessary to use the s_list_class function if there are at least> 3 of such calls. The fact is that calling such a function results in several queries to the database (from 5 and much more) (get a template, component data, etc.) On page If you need to output data from another component, then it is better to write a function for outputting this data to the default module functions.inc.php. In such a case, it is almost always possible to do with 1 request.
    In general, a single call to s_list_class can create dozens of queries to the database! Depending on the component whose objects are displayed.
  2. Forget about opt ​​() . Use (<if>? <True>: <false>)
    The thing is that even if the condition in opt returned false, the code will still be executed, but its result will not be displayed on the page.
  3. Be careful about using components with the "File" field . When displaying the list of objects of such a component, there will be a request to get data about the file as many times as there are objects. And if there are two such file fields, then there will be twice as many requests. If three, then three, etc.
    Those. if we have the “photo gallery” component and there are 2 “file” fields in it, then more than 20 queries to the database will be made to display the last 10 photos
    In general, requests in a loop are extreme evil! Avoid this.
  4. Almost the same situation with the vote. When displaying a poll, there will be as many queries to the database as there are answer options in it .
  5. Creating new components in which then will be sampled and sorted according to different conditions, put the necessary indices for the component table . This can significantly speed up his work.

However, on NetCat you can create quite large and complex projects. Just create them should people really understand the essence of what is happening inside the process. Therefore, instead of part of the internal functions of the system, it is better to use your own, written for a specific project. And it will be good if in the documentation for developers these moments reflect.

PS Appeal to the developers of NetCat (if they suddenly read) .
Please avoid database queries in a loop. Especially if it is not known in advance how many iterations will be in it. I really wanted these problematic functions to be rewritten. And also, it would be good to separately indicate in the documentation for developers if the function makes inquiries to the database, how much it produces them and what are the pitfalls.

Source: https://habr.com/ru/post/43485/


All Articles