⬆️ ⬇️

Snippet catalogView for MODx Evolution

I present to your attention the catalogView snippet. It was created for the new version of Shopkeeper - 1.0 (for MODx Evolution), but now you can use it instead of Ditto .



I did a little test of the performance of both snippets. We have 200 documents. You cannot cache snippets because pagination required. We took about average values ​​after several page updates.





')

Call Snippets:



[!catalogView?

&dataType=`documents`

&tpl=`@FILE:assets/snippets/catalogView/chunks/catalogRow_chunk.tpl`

&parents=`87`

&paginate=`1`

&display=`10`

&sortBy=`pagetitle`

&sortDir=`asc`!]




[!Ditto?

&tpl=`@FILE:assets/snippets/catalogView/chunks/catalogRow_chunk.tpl`

&parents=`87`

&paginate=`1`

&display=`10`

&sortBy=`pagetitle`

&sortDir=`asc`!]




10 documents per page





catalogView



MySQL: 0.0722 s, 6 request (s), PHP: 0.2756 s, total: 0.3479 s, document retrieved from cache




Ditto



MySQL: 0.1907 s, 32 request (s), PHP: 0.4672 s, total: 0.6579 s, document retrieved from cache




20 documents per page





catalogView



MySQL: 0.0735 s, 6 request (s), PHP: 0.2934 s, total: 0.3669 s, document retrieved from cache




Ditto



MySQL: 0.2601 s, 52 request (s), PHP: 0.5081 s, total: 0.7683 s, document retrieved from cache





As you can see, Ditto makes 2 MySQL queries per page. In the catalogRow_chunk.tpl chunk, there is one nonstandard PHx modifier that is used to change the format of the price number: [+ price: num_format +] . If it is removed the values ​​will be as follows (20 documents):



catalogView



MySQL: 0.0754 s, 5 request (s), PHP: 0.2794 s, total: 0.3548 s, document retrieved from cache




Ditto



MySQL: 0.2218 s, 32 request (s), PHP: 0.5411 s, total: 0.7629 s, document retrieved from cache





Strange, Ditto began to make significantly fewer requests. For each document is now one request. catalogView - less than one general request. I don’t know what the request is there for and why PHx does, because the modifier code is in the file, not in the database, but it doesn’t matter. I wondered why for each PHx-modifier (non-standard) when using Ditto, one request is made to the database, because PHx caches such modifiers.



Everything turned out to be simple. Ditto (2.1.0) does not allow PHx to cache modifiers, since when “rendering” each document, it creates a new object of the PHx class ( $ ditto-> render () function). Well, besides that, if you do not use PHx-modifiers from files, one request for each document is too much.



catalogView is not yet well tested, errors are possible. Please report bugs found.



Download catalogView 1.0 RC1



PS Of course, it's time to think about MODx Revo, but I decided to “finish off” Shopkeeper for MODx Evo by releasing version 1.0 (now beta).

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



All Articles