Snippets

How is snippets working?

6 months 1 week ago #93174

Octav A's Avatar Octav A

Hello,
Please tell me, is snippets component loading all snippets database when page with couple of snippets is loaded? I have issues with page loading and when checked page in debug i see the below query is causing the issue.
I use a table of around 100 000 snippets. Please confirm if this is as it should be. Thanks.

440.08 ms
SELECT a.*
FROM `tableprefix_snippets` AS `a`
WHERE ( `a`.`published` IN ( 0,1,2 ) )
ORDER BY a.published asc, a.ordering asc

6 months 1 week ago #93179

Peter van Westen's Avatar Peter van Westen Admin

Please try the latest development version from:
www.regularlabs.com/development-releases

6 months 1 week ago #93184

Octav A's Avatar Octav A

I have installed dev memory used size has decreased (according to debug console) but number of queries has inreased so that it crashes the browser to display.

6 months 1 week ago #93185

Peter van Westen's Avatar Peter van Westen Admin

How many snippet tags are you using on a page?
And you have 100.000 snippets?
Wow...
Snippets was never made with something like that in mind.

To me it sounds like you could probably use Snippets in a more effective way (or use ReReplacer instead).

Can you explain how you are using Snippets and why you need so many items?

6 months 1 week ago #93186

Octav A's Avatar Octav A

Actually around 70 000 which i use php to display geographical titles in current displayed language. I looks that i will have to do this in some other way. If any ideas pleas share. thanks

6 months 1 week ago #93187

Peter van Westen's Avatar Peter van Westen Admin

Can you give mote information on what these snippets contain and how/where you are calling them?

6 months 1 week ago #93188

Octav A's Avatar Octav A

alias: country-NL

content: {source}<?php echo JText::_('COUNTRY_NL'); ?>{/source}

{snippet country-NL}

the same for other geo names wich are much more numerous than countries

6 months 1 week ago #93189

Peter van Westen's Avatar Peter van Westen Admin

You could combine them all in to 1.
So instead of:

{snippet country-NL}
Use:
{snippet country|NL}

Snippet ID: country

content:
{source}<?php echo JText::_('COUNTRY_\1'); ?>{/source}

See: www.regularlabs.com/extensions/snippets/...ing-dynamic-snippets

6 months 1 week ago #93190

Octav A's Avatar Octav A

I have read tutorial but dont understand how to use this dynamic with language strings so that codes (NL,AMS) and ids can be used as unique identifiers. Would appreciate if you
show me what is the content of such dynamic snippet for multiple items NL,DE,FR,BE .....

6 months 1 week ago #93191

Peter van Westen's Avatar Peter van Westen Admin

I explained just that in my previous reply!

6 months 1 week ago #93192

Octav A's Avatar Octav A

My friend, this is magic! Too bad i did not ask before, now i have to change all snippets.
As i understand this will dramatically change performance of such operations, am I right? thanks for your time again.

6 months 1 week ago #93193

Peter van Westen's Avatar Peter van Westen Admin

You can use DB Replacer to bulk replace these.
Search:

{snippet country-
Replace:
{snippet country|

www.regularlabs.com/extensions/dbreplacer

6 months 1 week ago #93195

Octav A's Avatar Octav A

One more. What about text snippets (no php, no multilanguage)

alias: city-AMS, city-EIN, city-BRU
content: Amsterdam, Eindhoven, Brussels
{snippet city-AMS}

Any dynamic magic for such situation?
P.S. i am not tech guy so things that may be obvious for you for me may not

6 months 1 week ago #93196

Peter van Westen's Avatar Peter van Westen Admin

I am not sure why you would want to use Snippets or any type of plugin tag for this.
What is the advantage of writing '{snippet city-AMS}' instead of simply 'Amsterdam'.
As you say, these are not dynamic. So why bother with using Snippets for these short fixed words?

If you do want to use plugin tags for this, I would go the same route you did for the country stuff, so using language strings:

{snippet city|AMS}
{source}<?php echo JText::_('CITY_\1'); ?>{/source}
Way easier to maintain too.

Or alternatively use Snippets' big brother ReReplacer and use replace lists.

PS: I made some more improvements to how Snippets collects the data from the database. Please update to the latest dev version.
www.regularlabs.com/development-releases

6 months 1 week ago #93197

Peter van Westen's Avatar Peter van Westen Admin

PS: There are big advantages to using language strings for this type of stuff even if your site is not using multiple languages.

6 months 1 week ago #93198

Octav A's Avatar Octav A

On some pages we get only 'AMS' from third party (nothing else) and we need to display title on our side so we use something like this: {snippet city-<?php echo $city_code; ?>}
For this separate case it seems snippets is not what is require, i will think about. thanks for your time - the part with language strings and dynamic snippets is magic

6 months 1 week ago #93200

Peter van Westen's Avatar Peter van Westen Admin

You could also do something like this, if you don't want to use language strings:

Make a file, e.g. /myfiles/cities.php

<?php
$cities = [
   'AMS' => 'Amsterdam',
   'EIN' => 'Eindhoven',
   'BRU' => 'Brussels',
];

Then in your snippet:
{source require_once="myfiles/cities.php"}<?php 
   echo isset($cities['\1']) ? $cities['\1'] :  '';
?>{/source}

See: www.regularlabs.com/extensions/sourcerer...rial#including-files

6 months 1 week ago #93202

Octav A's Avatar Octav A

Very good, after some trial this is working fine:

{source}
<?php
require_once("myfiles/cities.php");
echo isset($cities['\1']) ? $cities['\1'] : '';
?> {/source}

Some more magic, only question if it is worth using such snippet combination when php file has around 10 000 entries.

6 months 1 week ago #93203

Peter van Westen's Avatar Peter van Westen Admin

Will be better than using 10.000 separate Snippets.

6 months 1 week ago #93205

Octav A's Avatar Octav A

🙂 Understood. Thanks - This was a very useful support and experience. appreciate your time