Textpattern Forum

You are not logged in. Register | Login | Help

#1 2012-05-10 10:54:28

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 249
Website

r3780 small question

The question of best practice programming.
Why two SQL queries with PHP code better than one SQL query?

/textpattern/lib/txplib_misc.php line 2127

$out = safe_field('user_html','txp_page',"name='error_".doSlash($code)."'");
if ($out === false)
$out = safe_field('user_html','txp_page',"name='error_default'");

vs

$out = safe_field('user_html','txp_page',"name='error_".doSlash($code)."' or name='error_default' order by name limit 1");

Thanks for the response.


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_meta | aks_header : Compress your pages on the fly

Offline

#2 2012-05-10 12:34:35

Gocom
Developer
Registered: 2006-07-14
Posts: 4,471
Website

Re: r3780 small question

Which comes first, error_Xavier or error_default?


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#3 2012-05-10 12:50:10

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 249
Website

Re: r3780 small question

IMHO, $code – is a numeric or blank.

error_000, error_999, error_ always will be first then error_default

or in Textpattern $code maybe a string?…

Upd: RFC2616 describe numeric codes from 100 to 505.

Last edited by makss (2012-05-10 13:01:22)


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_meta | aks_header : Compress your pages on the fly

Offline

#4 2012-05-10 12:59:45

Gocom
Developer
Registered: 2006-07-14
Posts: 4,471
Website

Re: r3780 small question

Status is just the name of the prefixed page template. As currently there are no actual set limitations what that name should be, the status can be anything.

Last edited by Gocom (2012-05-10 13:00:37)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#5 2012-05-10 13:12:18

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 249
Website

Re: r3780 small question

Gocom wrote:

Status is just the name of the prefixed page template. As currently there are no actual set limitations what that name should be, the status can be anything.

What about RFC2616 ?

Status used in txp_status_header($status); like header("HTTP/1.1 $status");


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_meta | aks_header : Compress your pages on the fly

Offline

#6 2012-05-10 13:22:49

Gocom
Developer
Registered: 2006-07-14
Posts: 4,471
Website

Re: r3780 small question

Sure, the header will be invalid, didn’t say otherwise. But. There is no validation. The function or its tag presentation doesn’t make sure that the used status numeric or that it passes as a HTTP status code.

Last edited by Gocom (2012-05-10 13:24:26)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#7 2012-05-11 10:15:29

wet
Developer
From: Lenzing, Austria
Registered: 2005-06-06
Posts: 3,091
Website

Re: r3780 small question

Let me explain my reasoning why I chose one patch over the other:

I consider the patch I merged into r3780 as a more robust and – imho even more important – a more legible solution. Exploiting side effects (like sort order) for program logic might be useful for time critical code paths where we want to squeeze out every single cpu cycle but in this case I’d rather have an obvious code path than a clever hack.

Offline

#8 2012-05-11 15:25:39

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 249
Website

Re: r3780 small question

Jukka, Robert, Thanks for the responses.


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_meta | aks_header : Compress your pages on the fly

Offline

Board footer

Powered by FluxBB