Discussion:
wp_get_sites cache/transient
Tom Barrett
2014-02-19 09:46:48 UTC
Permalink
Can anyone point me to where the data returned by this function is cached?

It is continuing to include a blog that was deleted days ago, I'm having to
check against get_blog_details() in order to stop SQL errors trying to look
up against tables that don't exist.

Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
Otto
2014-02-19 09:55:28 UTC
Permalink
The wp_get_sites function isn't cached. It selects the data directly from
the database. You can see the code yourself at the bottom of
wp-includes/ms-functions.php.

If you want it to not return deleted sites, you need to pass it deleted=0
as an argument.

-Otto
Post by Tom Barrett
Can anyone point me to where the data returned by this function is cached?
It is continuing to include a blog that was deleted days ago, I'm having to
check against get_blog_details() in order to stop SQL errors trying to look
up against tables that don't exist.
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Tom Barrett
2014-02-19 12:16:36 UTC
Permalink
It's not that it is set to be deleted, it is that the row in the database
has been deleted and the tables dropped (probably via the 'delete site'
network admin menu, but it's a dev environment with other developers).

I've not had time to look into something re-createable, but to illustrate
my point, this would be the pseudo-code steps to replicate the issue (the
aim being here to explain that there is no row in wp_blogs to match the
blogid that the function returns).

1. Set up WP Network
2. Create 2 new blogs (you now have blog IDs 1,2,3)
3. DELETE from wp_blogs WHERE blog_id=2
4. DROP tables like 'wp_2%'
5. $sites = wp_get_sites();

At this point, assuming the issue is that simple, $sites=array( 1, 2, 3 ),
even though blog 2 has been deleted.

That's why I assumed that the SQL cached somewhere.

I'll add a little context here, for any googling:
This is the code:
function tcb_find_blogs_to_archive(){
$blogs = wp_get_sites();
$archive = array();
foreach( $blogs as $blogid => $blog ){
$state = get_blog_option( $blogid, 'my_blog_state', 'live' );
if( $state == 'archive' ){
$archive[$blogid] = $blog;
}
}

return $archive;
}

Generates this error:
WordPress database error Table 'testdb.wp_4_options' doesn't exist for
query SELECT option_value FROM wp_4_options WHERE option_name =
'my_blog_state' LIMIT 1 made by require_once('wp-admin/admin.php')...

I don't understand how the 'deleted' argument would make any difference in
this case (unless it is being cached somewhere)?

Or am I just not grokking this? ;p
Post by Otto
The wp_get_sites function isn't cached. It selects the data directly from
the database. You can see the code yourself at the bottom of
wp-includes/ms-functions.php.
If you want it to not return deleted sites, you need to pass it deleted=0
as an argument.
-Otto
Post by Tom Barrett
Can anyone point me to where the data returned by this function is
cached?
Post by Tom Barrett
It is continuing to include a blog that was deleted days ago, I'm having
to
Post by Tom Barrett
check against get_blog_details() in order to stop SQL errors trying to
look
Post by Tom Barrett
up against tables that don't exist.
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
Dion Hulse (dd32)
2014-02-19 12:21:39 UTC
Permalink
If the database has been manually altered, and you're running an object
cache.. the simplest solution is to just reload your object cache (ie.
reload php-fpm, clear memcache, clear apc, whatever) and let WordPress fill
the caches back up.

If it's a development platform that shouldn't be an issue - and tell the
other developers not to alter raw data while there's caching involved next
time..
Post by Tom Barrett
It's not that it is set to be deleted, it is that the row in the database
has been deleted and the tables dropped (probably via the 'delete site'
network admin menu, but it's a dev environment with other developers).
I've not had time to look into something re-createable, but to illustrate
my point, this would be the pseudo-code steps to replicate the issue (the
aim being here to explain that there is no row in wp_blogs to match the
blogid that the function returns).
1. Set up WP Network
2. Create 2 new blogs (you now have blog IDs 1,2,3)
3. DELETE from wp_blogs WHERE blog_id=2
4. DROP tables like 'wp_2%'
5. $sites = wp_get_sites();
At this point, assuming the issue is that simple, $sites=array( 1, 2, 3 ),
even though blog 2 has been deleted.
That's why I assumed that the SQL cached somewhere.
function tcb_find_blogs_to_archive(){
$blogs = wp_get_sites();
$archive = array();
foreach( $blogs as $blogid => $blog ){
$state = get_blog_option( $blogid, 'my_blog_state', 'live' );
if( $state == 'archive' ){
$archive[$blogid] = $blog;
}
}
return $archive;
}
WordPress database error Table 'testdb.wp_4_options' doesn't exist for
query SELECT option_value FROM wp_4_options WHERE option_name =
'my_blog_state' LIMIT 1 made by require_once('wp-admin/admin.php')...
I don't understand how the 'deleted' argument would make any difference in
this case (unless it is being cached somewhere)?
Or am I just not grokking this? ;p
Post by Otto
The wp_get_sites function isn't cached. It selects the data directly from
the database. You can see the code yourself at the bottom of
wp-includes/ms-functions.php.
If you want it to not return deleted sites, you need to pass it deleted=0
as an argument.
-Otto
Post by Tom Barrett
Can anyone point me to where the data returned by this function is
cached?
Post by Tom Barrett
It is continuing to include a blog that was deleted days ago, I'm
having
Post by Otto
to
Post by Tom Barrett
check against get_blog_details() in order to stop SQL errors trying to
look
Post by Tom Barrett
up against tables that don't exist.
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Tom Barrett
2014-02-19 12:33:35 UTC
Permalink
There are no cache defines in wp-config.php

Neither memcache, nor apc are installed on the host.

I used the example of deleting table rows to emphasize that there is no row
(with 'deleted'=1) in the database.

So, I can see no reason why anything other than WordPress is caching the
existence of the blog.
Post by Dion Hulse (dd32)
If the database has been manually altered, and you're running an object
cache.. the simplest solution is to just reload your object cache (ie.
reload php-fpm, clear memcache, clear apc, whatever) and let WordPress fill
the caches back up.
If it's a development platform that shouldn't be an issue - and tell the
other developers not to alter raw data while there's caching involved next
time..
Post by Tom Barrett
It's not that it is set to be deleted, it is that the row in the database
has been deleted and the tables dropped (probably via the 'delete site'
network admin menu, but it's a dev environment with other developers).
I've not had time to look into something re-createable, but to illustrate
my point, this would be the pseudo-code steps to replicate the issue (the
aim being here to explain that there is no row in wp_blogs to match the
blogid that the function returns).
1. Set up WP Network
2. Create 2 new blogs (you now have blog IDs 1,2,3)
3. DELETE from wp_blogs WHERE blog_id=2
4. DROP tables like 'wp_2%'
5. $sites = wp_get_sites();
At this point, assuming the issue is that simple, $sites=array( 1, 2, 3
),
Post by Tom Barrett
even though blog 2 has been deleted.
That's why I assumed that the SQL cached somewhere.
function tcb_find_blogs_to_archive(){
$blogs = wp_get_sites();
$archive = array();
foreach( $blogs as $blogid => $blog ){
$state = get_blog_option( $blogid, 'my_blog_state', 'live' );
if( $state == 'archive' ){
$archive[$blogid] = $blog;
}
}
return $archive;
}
WordPress database error Table 'testdb.wp_4_options' doesn't exist for
query SELECT option_value FROM wp_4_options WHERE option_name =
'my_blog_state' LIMIT 1 made by require_once('wp-admin/admin.php')...
I don't understand how the 'deleted' argument would make any difference
in
Post by Tom Barrett
this case (unless it is being cached somewhere)?
Or am I just not grokking this? ;p
Post by Otto
The wp_get_sites function isn't cached. It selects the data directly
from
Post by Tom Barrett
Post by Otto
the database. You can see the code yourself at the bottom of
wp-includes/ms-functions.php.
If you want it to not return deleted sites, you need to pass it
deleted=0
Post by Tom Barrett
Post by Otto
as an argument.
-Otto
Post by Tom Barrett
Can anyone point me to where the data returned by this function is
cached?
Post by Tom Barrett
It is continuing to include a blog that was deleted days ago, I'm
having
Post by Otto
to
Post by Tom Barrett
check against get_blog_details() in order to stop SQL errors trying
to
Post by Tom Barrett
Post by Otto
look
Post by Tom Barrett
up against tables that don't exist.
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
Dion Hulse (dd32)
2014-02-19 12:48:54 UTC
Permalink
Well, if there's no caches defined, then it's not a WordPress caching issue
:)

Looking at wp_get_sites(), there is indeed no caching at all (as Otto
rightly pointed out), so even if WordPress DID have caching enabled it
wouldn't do anything.

So you've got a fault in either:
a) MySQL returning the wrong data - or caching the return (unlikely)
or
b) Something loaded in WordPress which is caching the query.
WordPress doesn't have query caching, so that points to a plugin or custom
DB dropin. W3 Total cache comes to mind as one plugin which does do query
caching.
Post by Tom Barrett
There are no cache defines in wp-config.php
Neither memcache, nor apc are installed on the host.
I used the example of deleting table rows to emphasize that there is no row
(with 'deleted'=1) in the database.
So, I can see no reason why anything other than WordPress is caching the
existence of the blog.
Post by Dion Hulse (dd32)
If the database has been manually altered, and you're running an object
cache.. the simplest solution is to just reload your object cache (ie.
reload php-fpm, clear memcache, clear apc, whatever) and let WordPress
fill
Post by Dion Hulse (dd32)
the caches back up.
If it's a development platform that shouldn't be an issue - and tell the
other developers not to alter raw data while there's caching involved
next
Post by Dion Hulse (dd32)
time..
Post by Tom Barrett
It's not that it is set to be deleted, it is that the row in the
database
Post by Dion Hulse (dd32)
Post by Tom Barrett
has been deleted and the tables dropped (probably via the 'delete site'
network admin menu, but it's a dev environment with other developers).
I've not had time to look into something re-createable, but to
illustrate
Post by Dion Hulse (dd32)
Post by Tom Barrett
my point, this would be the pseudo-code steps to replicate the issue
(the
Post by Dion Hulse (dd32)
Post by Tom Barrett
aim being here to explain that there is no row in wp_blogs to match the
blogid that the function returns).
1. Set up WP Network
2. Create 2 new blogs (you now have blog IDs 1,2,3)
3. DELETE from wp_blogs WHERE blog_id=2
4. DROP tables like 'wp_2%'
5. $sites = wp_get_sites();
At this point, assuming the issue is that simple, $sites=array( 1, 2, 3
),
Post by Tom Barrett
even though blog 2 has been deleted.
That's why I assumed that the SQL cached somewhere.
function tcb_find_blogs_to_archive(){
$blogs = wp_get_sites();
$archive = array();
foreach( $blogs as $blogid => $blog ){
$state = get_blog_option( $blogid, 'my_blog_state', 'live' );
if( $state == 'archive' ){
$archive[$blogid] = $blog;
}
}
return $archive;
}
WordPress database error Table 'testdb.wp_4_options' doesn't exist for
query SELECT option_value FROM wp_4_options WHERE option_name =
'my_blog_state' LIMIT 1 made by require_once('wp-admin/admin.php')...
I don't understand how the 'deleted' argument would make any difference
in
Post by Tom Barrett
this case (unless it is being cached somewhere)?
Or am I just not grokking this? ;p
Post by Otto
The wp_get_sites function isn't cached. It selects the data directly
from
Post by Tom Barrett
Post by Otto
the database. You can see the code yourself at the bottom of
wp-includes/ms-functions.php.
If you want it to not return deleted sites, you need to pass it
deleted=0
Post by Tom Barrett
Post by Otto
as an argument.
-Otto
Post by Tom Barrett
Can anyone point me to where the data returned by this function is
cached?
Post by Tom Barrett
It is continuing to include a blog that was deleted days ago, I'm
having
Post by Otto
to
Post by Tom Barrett
check against get_blog_details() in order to stop SQL errors trying
to
Post by Tom Barrett
Post by Otto
look
Post by Tom Barrett
up against tables that don't exist.
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Tom Barrett
2014-02-19 13:04:02 UTC
Permalink
No caching plugins active to my knowledge.

This is the list of all directories in /plugins/

all-in-one-seo-pack
broken-site-checker
debug-bar
debug-bar-extender
force-strong-passwords
gplus-comments
image-widget
limit-login-attempts
mce-table-buttons
media-links
meta-box
multiple-post-thumbnails
option-tree
plugin-toggle
posts-to-posts
redirection
regenerate-thumbnails
social-media-icons
user-switching
wordpress-importer
gravityforms
my-blog-management

Not all are in use. There are no mu-plugins. The bottom one is the plugin
calling wp_get_sites() (I grepped /wp-content/).

Anyway, I see that I have hit some edge case of my own making. Thanks for
trying to help. I'll be quiet now.

Hopefully I'll get the time to either move off the edge, or make it
re-creatable and submit as a bug (be that core, plugin or theme).
Post by Dion Hulse (dd32)
Well, if there's no caches defined, then it's not a WordPress caching issue
:)
Looking at wp_get_sites(), there is indeed no caching at all (as Otto
rightly pointed out), so even if WordPress DID have caching enabled it
wouldn't do anything.
a) MySQL returning the wrong data - or caching the return (unlikely)
or
b) Something loaded in WordPress which is caching the query.
WordPress doesn't have query caching, so that points to a plugin or custom
DB dropin. W3 Total cache comes to mind as one plugin which does do query
caching.
Post by Tom Barrett
There are no cache defines in wp-config.php
Neither memcache, nor apc are installed on the host.
I used the example of deleting table rows to emphasize that there is no
row
Post by Tom Barrett
(with 'deleted'=1) in the database.
So, I can see no reason why anything other than WordPress is caching the
existence of the blog.
Post by Dion Hulse (dd32)
If the database has been manually altered, and you're running an object
cache.. the simplest solution is to just reload your object cache (ie.
reload php-fpm, clear memcache, clear apc, whatever) and let WordPress
fill
Post by Dion Hulse (dd32)
the caches back up.
If it's a development platform that shouldn't be an issue - and tell
the
Post by Tom Barrett
Post by Dion Hulse (dd32)
other developers not to alter raw data while there's caching involved
next
Post by Dion Hulse (dd32)
time..
Post by Tom Barrett
It's not that it is set to be deleted, it is that the row in the
database
Post by Dion Hulse (dd32)
Post by Tom Barrett
has been deleted and the tables dropped (probably via the 'delete
site'
Post by Tom Barrett
Post by Dion Hulse (dd32)
Post by Tom Barrett
network admin menu, but it's a dev environment with other
developers).
Post by Tom Barrett
Post by Dion Hulse (dd32)
Post by Tom Barrett
I've not had time to look into something re-createable, but to
illustrate
Post by Dion Hulse (dd32)
Post by Tom Barrett
my point, this would be the pseudo-code steps to replicate the issue
(the
Post by Dion Hulse (dd32)
Post by Tom Barrett
aim being here to explain that there is no row in wp_blogs to match
the
Post by Tom Barrett
Post by Dion Hulse (dd32)
Post by Tom Barrett
blogid that the function returns).
1. Set up WP Network
2. Create 2 new blogs (you now have blog IDs 1,2,3)
3. DELETE from wp_blogs WHERE blog_id=2
4. DROP tables like 'wp_2%'
5. $sites = wp_get_sites();
At this point, assuming the issue is that simple, $sites=array( 1,
2, 3
Post by Tom Barrett
Post by Dion Hulse (dd32)
),
Post by Tom Barrett
even though blog 2 has been deleted.
That's why I assumed that the SQL cached somewhere.
function tcb_find_blogs_to_archive(){
$blogs = wp_get_sites();
$archive = array();
foreach( $blogs as $blogid => $blog ){
$state = get_blog_option( $blogid, 'my_blog_state', 'live' );
if( $state == 'archive' ){
$archive[$blogid] = $blog;
}
}
return $archive;
}
WordPress database error Table 'testdb.wp_4_options' doesn't exist
for
Post by Tom Barrett
Post by Dion Hulse (dd32)
Post by Tom Barrett
query SELECT option_value FROM wp_4_options WHERE option_name =
'my_blog_state' LIMIT 1 made by require_once('wp-admin/admin.php')...
I don't understand how the 'deleted' argument would make any
difference
Post by Tom Barrett
Post by Dion Hulse (dd32)
in
Post by Tom Barrett
this case (unless it is being cached somewhere)?
Or am I just not grokking this? ;p
Post by Otto
The wp_get_sites function isn't cached. It selects the data
directly
Post by Tom Barrett
Post by Dion Hulse (dd32)
from
Post by Tom Barrett
Post by Otto
the database. You can see the code yourself at the bottom of
wp-includes/ms-functions.php.
If you want it to not return deleted sites, you need to pass it
deleted=0
Post by Tom Barrett
Post by Otto
as an argument.
-Otto
Post by Tom Barrett
Can anyone point me to where the data returned by this function
is
Post by Tom Barrett
Post by Dion Hulse (dd32)
Post by Tom Barrett
Post by Otto
cached?
Post by Tom Barrett
It is continuing to include a blog that was deleted days ago, I'm
having
Post by Otto
to
Post by Tom Barrett
check against get_blog_details() in order to stop SQL errors
trying
Post by Tom Barrett
Post by Dion Hulse (dd32)
to
Post by Tom Barrett
Post by Otto
look
Post by Tom Barrett
up against tables that don't exist.
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
Frank Bueltge
2014-02-19 10:36:12 UTC
Permalink
Hi Tom,

the function cache via wp_cache_set(), but the expire is 0.
Maybe you have a other function, there change this expire value?
Loading...