Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2006-06-28 13:53:41

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: MySQL Abuse

One per comment. Seems fair.

Uh, if that is the case (a query per comment), no that’s bad.

Offline

#14 2006-06-28 13:57:55

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: MySQL Abuse

Yeah,

I’d like to get that down to 34! Give me a day or two to think about the best way to cache the results of the comparisons the first time they are done.


Steve

Offline

#15 2006-06-28 14:05:24

M_i
Member
Registered: 2006-03-05
Posts: 122

Re: MySQL Abuse

Mary wrote:

Uh, if that is the case (a query per comment), no that’s bad.

This is what shows up in my debugging mode:

<txp:comments/> [SQL (0.000107): select Form from `txp_form` where `name` = ‘comments’ limit 1] [Form: comments] [SQL (0.000144): select *, unix_timestamp(posted) as time from `txp_discuss` where parentid=‘565’ and visible=1 order by posted asc] <txp:sed_get_comment_class hide_odd_even='1' /> [SQL (0.000097): SELECT name,RealName,email FROM txp_users WHERE name=’[authorsname]’ LIMIT 1] <txp:if_comments_preview> [<txp:if_comments_preview>: false] </txp:if_comments_preview> <txp:message/> <txp:comment_name/> <txp:comment_time/> <txp:comment_permlink> </txp:comment_permlink>

<br />
and then the part from <txp:sed_get_comment_class hide_odd_even='1' /> on is repeated for every comment.

Last edited by M_i (2006-06-28 14:06:03)

Offline

#16 2006-06-28 14:08:04

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: MySQL Abuse

Yep, just looked at the code, should be able to reduce it to one extra query for the whole comment list, even without caching.

I put the code to pull the author details in the per-comment call instead of making it outside the per-comment call. Will fix.

Speaking too fast. More details when I have more brain cycles on it.

Last edited by net-carver (2006-06-28 14:09:51)


Steve

Offline

#17 2006-06-28 14:36:04

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: MySQL Abuse

Steve: pull them into array, declare it as static and check for isset.

Offline

#18 2006-06-28 14:48:39

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: MySQL Abuse

Mary,

Thanks for that pointer. I haven’t used statics in PHP before so I’ll read up first just to check they are like C/C++. If they are then that might be the way to go but for now I have reduced the query count a slightly different way so it’s only needed once per article.

I just made the variable a global and use isset: if it’s not initialised, make the SQL call and populate the variable, otherwise just go with the existing value.

Working a treat on my localhost.

Any blaring klaxon’s with that approach?

Last edited by net-carver (2006-06-28 16:28:44)


Steve

Offline

#19 2006-06-28 16:27:29

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: MySQL Abuse

Mary,

further to the last post. Yes, now I’ve had a little read on static I’ll be switching over to it, there is no need for the value to be global as it’s only used in the one routine.

Thank you muchly.


Steve

Offline

#20 2006-06-28 16:42:26

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: MySQL Abuse

All,

sorry about that. There is a caching version of the comment pack now available. It reduces the overhead to one query per page (if it has any comments at all).


Steve

Offline

#21 2006-06-28 17:54:04

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: MySQL Abuse

Well… urgent help needed :D (and first: excuse the “technical” language I use about mysql, queries, etc…)

After reading this thread, I decided to take a deeper look to the tag trace.
I was having +300 queries, but I didn’t care too much.

But, as I said, I decided to make a tag trace and I have found something that makes me fear.
I dont know how to explain this… let me see…

In all my pages, there are many many queries made by txp:bas_lightbox even when I’m not “using” the plug-in in the page template…

So, the thing I have found is that each time a query calls an article that has <txpbas_lightbox /> inside the body, that tag is procesed! (this is when those many many queries to the database are made) even when the viewed page isn’t using/displaying that plug-in
:(

Example:

A simple <txp:article_custom section="fotolog" form="permlink" limit="1" /> will generate all the following tag trace!! (the “permlink” form is just a <txp:permlink />).

<pre><code>
&#60;txp&#58;article&#95;custom section&#61;&#34;fotolog&#34; form&#61;&#34;permlink&#34; limit&#61;&#34;1&#34; &#47;&#62;

&#91;SQL &#40;0&#44;352279&#41;&#58; select &#42;&#44; unix&#95;timestamp&#40;Posted&#41; as uPosted from &#96;textpattern&#96; where 1 and Status&#61;&#39;4&#39; and Posted &#60; now&#40;&#41; and Section &#61; &#39;fotolog&#39; order by Posted desc limit 0&#44; 1&#93;

&#91;SQL &#40;0&#44;000446&#41;&#58; select Form from &#96;txp&#95;form&#96; where &#96;name&#96; &#61; &#39;permlink&#39; limit 1&#93;

&#91;Formulario&#58; permlink&#93; &#91;art&#237;culo 39&#93; &#60;txp&#58;bas&#95;lightbox wraptag&#61;&#34;div&#34; wrapclass&#61;&#34;thumbs&#34; img&#61;&#34;121&#44;120&#44;119&#44;118&#44;117&#44;116&#44;115&#44;114&#44;109&#44;80&#44;113&#44;112&#44;111&#44;110&#44;107&#44;106&#44;104&#44;90&#44;89&#44;92&#44;88&#44;93&#44;83&#44;82&#44;81&#34;&#47;&#62;

&#91;SQL &#40;0&#44;037095&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;121&#39; limit 1&#93; &#91;SQL &#40;0&#44;000191&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;121&#34;&#93;

&#91;SQL &#40;0&#44;000184&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;120&#39; limit 1&#93; &#91;SQL &#40;0&#44;000141&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;120&#34;&#93;

&#91;SQL &#40;0&#44;000178&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;119&#39; limit 1&#93; &#91;SQL &#40;0&#44;000162&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;119&#34;&#93;

&#91;SQL &#40;0&#44;000182&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;118&#39; limit 1&#93; &#91;SQL &#40;0&#44;000146&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;118&#34;&#93;

&#91;SQL &#40;0&#44;000188&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;117&#39; limit 1&#93; &#91;SQL &#40;0&#44;000142&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;117&#34;&#93;

&#91;SQL &#40;0&#44;000177&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;116&#39; limit 1&#93; &#91;SQL &#40;0&#44;000142&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;116&#34;&#93;

&#91;SQL &#40;0&#44;000186&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;115&#39; limit 1&#93; &#91;SQL &#40;0&#44;000143&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;115&#34;&#93;

&#91;SQL &#40;0&#44;000181&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;114&#39; limit 1&#93; &#91;SQL &#40;0&#44;000139&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;114&#34;&#93;

&#91;SQL &#40;0&#44;000177&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;109&#39; limit 1&#93; &#91;SQL &#40;0&#44;000139&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;109&#34;&#93;

&#91;SQL &#40;0&#44;004232&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;80&#39; limit 1&#93; &#91;SQL &#40;0&#44;000147&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;80&#34;&#93;

&#91;SQL &#40;0&#44;000178&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;113&#39; limit 1&#93; &#91;SQL &#40;0&#44;000142&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;113&#34;&#93;

&#91;SQL &#40;0&#44;000178&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;112&#39; limit 1&#93; &#91;SQL &#40;0&#44;000141&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;112&#34;&#93;

&#91;SQL &#40;0&#44;000176&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;111&#39; limit 1&#93; &#91;SQL &#40;0&#44;000146&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;111&#34;&#93;

&#91;SQL &#40;0&#44;000179&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;110&#39; limit 1&#93; &#91;SQL &#40;0&#44;000137&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;110&#34;&#93;

&#91;SQL &#40;0&#44;000178&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;107&#39; limit 1&#93; &#91;SQL &#40;0&#44;000142&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;107&#34;&#93;

&#91;SQL &#40;0&#44;000175&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;106&#39; limit 1&#93; &#91;SQL &#40;0&#44;000137&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;106&#34;&#93;

&#91;SQL &#40;0&#44;000185&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;104&#39; limit 1&#93; &#91;SQL &#40;0&#44;000155&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;104&#34;&#93;

&#91;SQL &#40;0&#44;000174&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;90&#39; limit 1&#93; &#91;SQL &#40;0&#44;000137&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;90&#34;&#93;

&#91;SQL &#40;0&#44;000171&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;89&#39; limit 1&#93; &#91;SQL &#40;0&#44;000138&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;89&#34;&#93;

&#91;SQL &#40;0&#44;000182&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;92&#39; limit 1&#93; &#91;SQL &#40;0&#44;000146&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;92&#34;&#93;

&#91;SQL &#40;0&#44;000174&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;88&#39; limit 1&#93; &#91;SQL &#40;0&#44;000139&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;88&#34;&#93;

&#91;SQL &#40;0&#44;000176&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;93&#39; limit 1&#93; &#91;SQL &#40;0&#44;000145&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;93&#34;&#93;

&#91;SQL &#40;0&#44;000176&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;83&#39; limit 1&#93; &#91;SQL &#40;0&#44;000138&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;83&#34;&#93;

&#91;SQL &#40;0&#44;000176&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;82&#39; limit 1&#93; &#91;SQL &#40;0&#44;000141&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;82&#34;&#93;

&#91;SQL &#40;0&#44;000180&#41;&#58; select &#42; from &#96;txp&#95;image&#96; where id&#61;&#39;81&#39; limit 1&#93; &#91;SQL &#40;0&#44;000143&#41;&#58; select id&#44; ext&#44;caption from &#96;txp&#95;image&#96; where id &#61;&#34;81&#34;&#93;

&#60;txp&#58;permlink&#47;&#62;
</code></pre>

Why are all this calls made?
I’m not even procesing/calling the “body” of the called article, I just need the “permlink”.

Of course, this happen also in generated articles-list where I only show the excerpt, but for some reason, all the queries to the bas_lightbox are also made! (why??!!) :(

That’s the reason why I’m having +300 queries in the homepage and even +70 in a simple contact page!

Last edited by maniqui (2006-06-28 17:57:30)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#22 2006-06-28 18:18:55

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: MySQL Abuse

Sorry for being the double post and the little off topic.

Here is a home page tag trace
Look all the queries made to the DB by bas_lightbox, even when I’m not using that plug-in in the home-page.

Thanks in advance.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#23 2006-06-28 18:39:09

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: MySQL Abuse

You need to talk with the author of the plugin, if you have plugin specific questions.

Textpattern has always fetched and processed the article-body, even in lists that don’t explicitly call the body-tag. Changes had been considered in the past but dropped because we were not sure if any plugins rely on that behaviour. If I am not mistaken Alex finall checked in the change (which will roll out in 4.0.4) after no indication was found that any plugins actually do rely on it. Unless there are complaints before the next release, it’ll probably stay in.

Offline

#24 2006-06-28 18:52:02

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: MySQL Abuse

Thanks, Sencer.
I have asked at the plug-in thread and wet gave me a similar answer.

I will have to rethink the use of that plug-in in the article bodies…


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB