[wp-hackers] Avoid query_post on frontpage on wp initialization
Andrew Nacin
wp at andrewnacin.com
Tue Dec 28 05:27:11 UTC 2010
On Mon, Dec 27, 2010 at 4:33 PM, Mike Schinkel
<mikeschinkel at newclarity.net>wrote:
> On Dec 27, 2010, at 4:07 PM, Martin Widmann wrote:
> > we are running on a pretty big WP database with a very large posts table
> with ~500k entries in the posts table. When going to the front page of the
> blog a query to the wp_posts table is made during WP initialization. This
> default query on the big table takes ~1sec. The data returned by this query
> is not required afterwards, so I'd like to avoid doing it.
> >
> > In wp->main() the query_posts() is always executed and I don't seem to
> have very much control of what is queried in there. I'd like to avoid
> querying anything at this stage at all. Later on in the page flow I'll query
> the database differently. Any idea?
>
> Hi Martin,
>
> Yes, there are unfortunately no hooks to disable running of the first
> query. I seem to remember it being one of my first trac tickets (though I
> can't find it now) though it didn't get any traction.
>
> For the longest time I was at a lost for how to resolve the issue without
> hacking core and recently I think I identified a solution. If you subclass
> the WP class you can bypass the get_posts() function for the root, or call
> the standard one otherwise. Here's some code to try.I haven't fully tested
> it but it should get you started:
Simply extending the WP class would indeed be the right way to do this.
More information about the wp-hackers
mailing list