Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

A New, Interesting Feature For 4.13 Rate Topic   * * * * * 1 votes

 
  • harmsmitsdev
  • Senior Member
  • Members
  • Join Date: 22-Feb 20
  • 159 posts

Posted 12 April 2021 - 07:32 AM #1

Since end of 2020, I have been working on bringing some new features to CS-Cart myself. One of the things every developer should know of, which can greatly help, is `multiquery`. MultiQuery is a concept where one can send multiple queries in one go to the database.

 

Why should you use multi query? Well, in some *larger* environments, there simply is a round robin time for queries, which can easily be as high as ~.5ms. Now, Cs-Cart by default requires about 60 queries for a normal page. A product page will take up a hundred or so. MultiQuery offers a partial solution in this case, where it will allow you to send multiple queries at once to the database.

 

Its really easy to use, and only requires people to have defined the 'Mysqli' backend for their database (NOT PDO). Over the next few months, I will need to spot some areas where these things can be used, but one that you will immediately see is in `fn.images.php`; Usage is as follows:

list($query1, $query2) = db_multi_query([
    [
        MultiQueryTypes::ARR,
        'SELECT * FROM ?:products LIMIT 5',
    ],
    [
        MultiQueryTypes::HASH,
        'order_id',
        'SELECT * FROM ?:orders LIMIT 5',
    ],
]);

`\Tygh\Enum\MultiQuerTypes` holds all available types of querying in CsCart, think about `db_get_row`, `db_get_field`, `db_get_fields`, `db_get_array`, etc. The `db_multi_query` function will keep its array indices, meaning you could also directly assign it to the view controller with predifined offsets if you really want.

 

You can dynamically construct the array to bundle a lot of common queries if you prefer. But please mind, this is no excuse for bad queries. There are simply scenarios where one will require a variety of queries, since a UNION won't work, and that is what this is intended for.

 

In 4.14 I might add 'async' functions (if time permits) for this as well, where it will execute a stack of queued functions once a result is resolved, or when a blocking query is executed. This should greatly help to get some better performance for environments with high round robin times, especially since you can lift on queries CS-Cart already sends.

 

Anyways, I thought I'd bring this to your attention since most of this stuff never makes it into the release log.
 


harmsmitsdev@gmail.com


 
  • 12ka4
  • Senior Member
  • Trial users
  • Join Date: 21-Feb 18
  • 263 posts

Posted 26 April 2021 - 04:41 PM #2

Thanks for the info..I shall reach out to you.