Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-06-27 19:11:36

Myusername
Member
Registered: 2019-12-12
Posts: 162

two ways to do the same thing, which is better?

In terms of performance, which one is recommended?

<meta property="og:image" content="<txp:images name='header-image-<txp:section/>' limit="1"><txp:image_url/></txp:images>">
<meta property="twitter:image" content="<txp:images name='header-image-<txp:section/>' limit="1"><txp:image_url/></txp:images>">

or

<txp:variable name="head_image"><txp:images name='header-image-<txp:section/>' limit="1"><txp:image_url/></txp:images></txp:variable>
<meta property="og:image" content='<txp:variable name="head_image"/>'>
<meta property="twitter:image" content='<txp:variable name="head_image"/>'>

Offline

#2 2021-06-27 21:47:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: two ways to do the same thing, which is better?

Not sure there’s much difference in raw performance. If memory serves, we cache the image requests (I’d have to check to be sure). But from a don’t-repeat-yourself and easier-to-maintain standpoint, option 2 is better as you only define the container once. Only one place to alter things if you want to change stuff in future.

FWIW, there’s also another variant, even shorter, and without the <txp:variable> dance:

<txp:images name='header-image-<txp:section/>' limit="1">
   <meta property="og:image" content="<txp:image_url />">
   <meta property="twitter:image" content="<txp:image_url />">
</txp:images>

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2021-06-28 07:39:13

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: two ways to do the same thing, which is better?

Bloke wrote #330755:

Not sure there’s much difference in raw performance. If memory serves, we cache the image requests (I’d have to check to be sure).

Not sure we do, so your FWIW variant for me.

Offline

#4 2021-06-28 09:40:20

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: two ways to do the same thing, which is better?

This is probably a hopelessly stupid idea…but could Debugging model tuned to show the time taken for each query, as well as the final total?

Offline

#5 2021-06-28 10:34:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: two ways to do the same thing, which is better?

gaekwad wrote #330770:

could Debugging model tuned to show the time taken for each query, as well as the final total?

It kind of does, I think. By showing the start time of each query and its duration. Do you mean even more granular?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2021-06-28 10:47:31

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: two ways to do the same thing, which is better?

Bloke wrote #330773:

It kind of does, I think. By showing the start time of each query and its duration.

You’re right. I could’ve sworn it was just a summary. Mea culpa.

Offline

#7 2021-06-28 13:50:13

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: two ways to do the same thing, which is better?

gaekwad wrote #330770:

This is probably a hopelessly stupid idea…but could Debugging model tuned to show the time taken for each query, as well as the final total?

Absolutely nothing wrong with this, just a different approach.

Offline

Board footer

Powered by FluxBB