Support Forum

After upgrade dbqueries increased!

33 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

Our ‘News’ page is similar in that it has small excerpts from various posts (ALL of which are linked to forum topics) but the link query is only actioned once and that is for the actual main post. So I think this comes down to the way the blog post excerpts are being called an compiled on your home page and that is what we need to try and pin down.

YS Yellow Swordfish
Yellow Swordfish
Member

Would you be willing to make small code edits on your staging server so we can try and isolate the WP hook(s) that is getting called by our home page?

WI WilRC
WilRC
Member

Sure no problem, staging is the best environment for testing!

YS Yellow Swordfish
Yellow Swordfish
Member

Excellent. I went to your staging site and turned Blog Linking back on just so I could try a few settings. No help yet. And I am not really sure where to start as the obvious things didn’t seem to help.

And before we go any further – if you haver any caching in place on the staging server could you turn t off while we run some tests?

The file you need to look at is-  by default – at /wp-content/sp-resources/forum-plugins/blog-linking/sp_linking_plugin.php

It starts with a whole swathe of ‘add_action’ and ‘add_filter’ directives. If possible, I would like you to comment some of these out, one at a time, to see if you can find the main culprit. I think for starters the ones we need to work with are:

sph_setup_forum‘ (see note below)
the_content
the excerpt
sph_blog_support_start
sph_aioseo_canonical_url
sph_canonical_url

Please note that ‘spf_setup_forum‘ has 2 entries. Please test them 1 at a time.
the_content‘ and ‘the_excerpt‘ should be tested individually and then again together.

Is this all doable?

WI WilRC
WilRC
Member

This is doable no problem at all!

We don’t use a cache plugin.

Testresults:

1 at the time

Line 64: add_action(‘sph_setup_forum’,    ‘sp_linking_check_delete_action’);
Queries decreased 255 to 248

Line 120: add_action(‘sph_setup_forum’,     ‘sp_linking_break_listen’);
Queries decreased 255 to 247

Together: 255 to 245

Line 67:                add_filter(‘the_content’,      ‘sp_linking_show_blog_link’);
Queries decreased 255 to 245

Line 68:                add_filter(‘the excerpt’,   ‘sp_linking_show_blog_link’);
Queries decreased 255  to 247

Together: 255 to 255

Line 111: add_action(‘sph_blog_support_start’,     ‘sp_linking_canonical_url’, 1, 1);
Queries decreased  255 to 247

Line 112: add_filter(‘sph_aioseo_canonical_url’,  ‘sp_linking_aioseo_caninical_url’, 1, 2);
Queries decreased 255 to 248

Line 113: add_filter(‘sph_canonical_url’,  ‘sp_linking_switch_canionical_url’);
Queries decreased 255 to 247

None of these are resposible for the queryload!

I did some extra testing. Get comments number is suspicious!
Line 75:      add_filter(‘get_comments_number’,  ‘sp_comments_count_filter’, 1, 2);
Queries decreased from 255 to 160

Line 497:   remove_filter(‘get_comments_number’, ‘sp_comments_count_filter’, 1);
Queries decreased 255 to 161

Together: 255 to 160

I think we’ve found the main culprit in the get_comment action and filter!?

KR,

Wil

MP Mr Papa
Mr Papa
Member

sorry, will have to wait for @yellow-swordfish to return in the am…

YS Yellow Swordfish
Yellow Swordfish
Member

Ah… is that what the numbers are against each of the little extracts? Comment counts?

Seems like a pretty unique situation which is why, I guess, it hasn’t come up before. Seems that probably the best solution would be to cache the data which would result in one read per post instead of multiple. Let me see what I can work out today and then I can ask you to change the code and test. OK?

YS Yellow Swordfish
Yellow Swordfish
Member

Let’s try this. Same file as before but this time right down the very bottom is the function:

sp_blog_links_control()

On the line before the switch command at the top can you insert the line:

static $bLinks = array();

and then we will change the case ‘read’ code to be:

if(!array_key_exists($postid, $bLinks)) $bLinks[$postid] = spdb_table(SFLINKS, "post_id=$postid", 'row');
return $bLinks[$postid];
break;

and see if that helps out. I would be quite happy to make this part of the permanent code.

WI WilRC
WilRC
Member

I have adjusted the code.

Works great. Queries decreased 255 to 162. Perfect solution.

Thanks for the support and service 🙂

YS Yellow Swordfish
Yellow Swordfish
Member

Good news. Consider that code as being in the next plugin update.

WI WilRC
WilRC
Member

Sorry YS, we were cellebrating to soon. With the code adjustments the blog link disapeared on the article page. You have the option in the editor to add a blog link but it doesn’t show up!

YS Yellow Swordfish
Yellow Swordfish
Member

Can you check the options in the admin, There is a possibility i turned it off and forgot to turn it on again. Plus the changes we made today would not have that effect

WI WilRC
WilRC
Member

The blog link plugin is turned on. On the article page the Forumlink is disapeared. Undo the code changes will show up the forumlink again. There is a get_comments code in my themefunctionsfile, could that be responsible for the extra queryload on the frontpage together with the bloglinkfunction.

The get_comments is a part of the recentcomment widget!

YS Yellow Swordfish
Yellow Swordfish
Member

Bit we did nothing to stop the blog link showing up. All we did was cache the results so that ot did not perform more than 1 database query for each post ID.
What about the filter.action hooka at the top? They should ALL now be uncomnented and running. Are they?