Do you have some feature in mind that you'd love to see in Couch? Let us know.
9 posts Page 1 of 1
Hi! It would be great to implement an attribute which makes Couch to not evaluate embedded code. If you embed a huge static asset without checking if there are any couch tags present inside(Couch parser turned off for embedded asset) it would boost performance a lot. Thank you!
Could you post your static sample and instructions to repeat performance test? Is performance hit noticeable on your end? In case it is a real issue, I'll get you a code for modded embed or a new tag..
Sorry but it is only an assumption. I cannot run any tests as I can not turn off Couch parser myself but I can only assume that for my static assets(~30kb of html) it could make a noticeable difference if the code would not be evaluated at all.
It can be of great help to have such a behavior. I've implemented sort of partial cache. Couch cache helps a lot but if your website has lots of pages(several hundred or more) and gets updated regularly - some users may see a delay for pages at first load. So i've managed to take out big portions of code which are present on all pages and generate an html file by using php snippet so it only takes time for one page to generate part of a website. All the other pages take this part as it is without any DB queries involved. It took page generation time from ~2000ms to ~400ms. So I thought that it would be fantastic if Couch could just include those files without looking into them. Sample code of partial cache is very simple:

Code: Select all
<cms:if "<cms:exists "cache/SOME_PAGE_SECTION" />" >
  <cms:embed "cache/SOME_PAGE_SECTION" />
<cms:else />
  <cms:capture into="section" >
    <cms:embed "partials/SOME_PAGE_SECTION_CODE" />
  </cms:capture>
  <cms:php>
    global $CTX;
    $contents = $CTX->get('section');
    file_put_contents( K_COUCH_DIR . "../" . K_SNIPPETS_DIR . "/cache/section.html" , $contents);
  </cms:php>
  <cms:show section />
</cms:if>
Let me explain.
I see your posted code and understand what you are trying to do schematically. For example, there is some dropdown input with list of country's cities - where a company has offices - say 1000 cities. Building the list of cities via cms:pages takes time (1 sec).

This operation is needed only once - every time the company closes an office in a city or adds an office in a new city. All the other reasons to bust html cache provided by Couch - i.e. editing any content of any page - also busts this dropdown list and cities list must be rebuild. Of course, this is what you see - first user generating Couch-powered cache will have a slow load of the page.

You do it okay - by embedding a file with results and if that is not present you generate one via embedding a file with code that has a different name (you may use cms:write for saving the file - check viewtopic.php?f=8&t=11377). However, your original question was implying that cms:embed is slow, while it is not so.

If you use cms:embed to load a file with code - it will take time for that code to execute. But if you load a pure generated html with cms:embed - it will be very quick, because it doesn't contain any code in it. If you have a sample that troubles you - please post it.
Let me also repeat my example with all codes, so it might be useful for others -

Some form is being built with cities dropdown and we want to optimize the following code for the first user who requested page without present Couch cache of that complete page -
Code: Select all
<cms:input type='dropdown' name='cities' 
       opt_values="<cms:pages masterpage='cities.php' skip_custom_fields='1' limit='100000' >
                       <cms:show k_page_title /><cms:if k_paginated_bottom = '0'>|</cms:if>
                   </cms:pages>"
/>


We can optimize it like this -
Code: Select all
<cms:if "<cms:not "<cms:exists 'cache/cities_html.inc' />" />" >
<cms:write 'snippets/cache/cities_html.inc' truncate='1'>
    <cms:embed 'cache/cities_code.inc' />
</cms:write>
</cms:if>
<cms:input type='dropdown' name='cities' opt_values="<cms:embed 'cache/cities_html.inc' />" />


Where cities_code.inc file would look like -
Code: Select all
<cms:pages masterpage='cities.php' skip_custom_fields='1' limit='100000' >
   <cms:show k_page_title /><cms:if k_paginated_bottom = '0'>|</cms:if>
</cms:pages>


And you can place similar code to manually rebuild cache by, for example, visiting cities.php non-executable template which only updates the snippet with cities.
Code: Select all
<cms:write 'snippets/cache/cities_html.inc' truncate='1'>
    <cms:embed 'cache/cities_code.inc' />
</cms:write>


As a last thing - It can be effective in case there are multiple parts of such "custom caches" and multiple places of where a cities list is needed. If your website only has one "heavy" page - then it might be useful to instruct admins to visit that page in browser..

Alternative idea - hook on event which triggers after page is saved in backend by admin - and request an url in background anonymously via curl (can employ this function here - https://github.com/trendoman/utility-fu ... e_url.html ). It will definitely build the desired cache for a given url.
Thank you for your reply! So you are saying that Couch's parser takes too little time so it won't make any difference if it evaluates it or not?
andreyzagoruy wrote: Thank you for your reply! So you are saying that Couch's parser takes too little time so it won't make any difference if it evaluates it or not?

That's right. Evaluation takes too little time to be noticed. Execution time depends on code.
Hello guys

Unfortunately, I did not see this topic and I had to come to Anton's decision entirely alone :D
Actually, let me report the situation -

Perhaps any website has content that changes very rarely:
- Mega menus in the header of all pages
- Dropdown menus at certain locations with a very large number of options
- Graphic slider on homepage
- Graphic slider in internal pages
- Footer
- Others

All this changes, for example, once in a year, but each load on any page of the site calculates everything and again all ...
Inevitably the site becomes slower!
Of course, we activate the built-in caching of the Couch, but let's imagine the site has 100,000 pages - that is, once all of these pages are loaded once, the cache will begin to help.

That small and highly underestimated tag is coming here with enormous power
<cms:write> is not only used to issue invoices, you can actually make any site much lighter and faster!
9 posts Page 1 of 1