Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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

#25 2006-06-28 19:07:16

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

Re: MySQL Abuse

Sencer wrote:

Textpattern has always fetched and processed the article-body, even in lists that don’t explicitly call the body-tag.

What does that mean, exactly?
Would that mean that if you produce a list of articles that have a whole lot of text in them, that would take a whole lot longer than producing a list of articles with only a little bit of text in them, even if all you’re displaying in the list is the article’s title?

On your recommendation, I went looking for any queries that take a lot longer than the others, and the only ones that really stood out were those called by txp:article (or (chh_)article_custom) to produce lists.
Could that be because the some of my most recent articles happen to have a fair amount of text in them?

Offline

#26 2006-06-28 19:58:55

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

Re: MySQL Abuse

Would that mean that if you produce a list of articles that have a whole lot of text in them, that would take a whole lot longer than producing a list of articles with only a little bit of text in them, even if all you’re displaying in the list is the article’s title?

In almost all cases: No – because Textpattern stores the posts with textile processed. Meaning there will be no measurable difference. Only txp-tags are stored as-is and processed on view, which usually doesn’t have any measurable negative effect either – the exception being plugin-calls that do db-queries. But like I said, this will probably change in 4.0.4 anyhow…

Offline

#27 2006-06-29 03:35:59

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

Re: MySQL Abuse

Sencer wrote:

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.

Sencer, that behaviour is currently needed by some localisation plugins, but it could be worked around. Graeme’s recently posted plugin and one I am working on locally need to be able to localise articles for display in multi-lingual sites and both rely on the article body being parsed, even if the body content isn’t displayed. This is needed for switching the article title to the correct language, important in article lists, lists of links etc, where the body isn’t needed.

Thinking aloud about options to get around this…

  • Would it be possible to make the parsing of article data an admin-configurable option so that those, relatively few plugins could keep the behaviour?
  • Add a new event, at the end of populating the article data (even if the body and excerpt are unparsed), that plugins could register a handler for, that would allow them to switch the title etc, according to the language settings, before the title is used?
  • We re-evaluate implementation strategies for multi-lingual plugins in light of this.

Thanks for the warning about this change, hope we can work something out.


Steve

Offline

#28 2006-06-29 04:33:18

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: MySQL Abuse

A simpler solution: plugins that require a parsed article body can simply parse it.

Whatever the solution, the body parse changes are available for all to test and debug.


Alex

Offline

#29 2006-06-29 08:17:50

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

Re: MySQL Abuse

Alex,

Will take a look over the next couple of days and post back to your referenced thread.

Thanks for the pointer.

Edit: Some feedback posted here.

Last edited by net-carver (2006-06-29 12:20:59)


Steve

Offline

#30 2006-06-29 16:31:06

graeme
Plugin Author
Registered: 2004-06-21
Posts: 337
Website

Re: MySQL Abuse

net-carver,

zem wrote:

A simpler solution: plugins that require a parsed article body can simply parse it.

For your information this is why my plugin didn’t break after r1303 – a simple return parse($thing);

Offline

Board footer

Powered by FluxBB