Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin cache issue if post has 0 items #11

Open
jorgenhorstink opened this issue Mar 31, 2011 · 2 comments
Open

Plugin cache issue if post has 0 items #11

jorgenhorstink opened this issue Mar 31, 2011 · 2 comments

Comments

@jorgenhorstink
Copy link

I solved a cache issue in the previous version of the plugin, but the last update reversed it. So I thought, lets create an issue. If an item has 0 replies, the plugin won't hit the cache, despite the fact that that a cache record is available. This is caused by wrongly testing if a cache record exists.

The fbComments_combineCommentCounts method uses get_option to check if a wordpress option exists. By definition this method returns a null value if the item does not exist. The if-statement should check for this null value, because if the option exists but returns 0 (zero replies yet), it won't hit the cache, and connects with facebook.

fix: check for null

// Return the cached comment count (if it exists)
if (get_option("fbComments_commentCount_$xid") !== null) {
    return fbComments_getCachedCommentCount($xid, $value);
}
@shaund
Copy link
Owner

shaund commented Apr 17, 2011

Cheers :) I'll integrate it into the next version.

@shaund shaund closed this as completed Apr 17, 2011
@rsantiago
Copy link

This cache problem will continue with this proposed solution.

That's because, according to the wordpress documentation, the return for the get_option is FALSE in case there's no value to the requested option. Quoting the documentation:

Description

"A safe way of getting values for a named option from the options database table. If the desired option does not exist, or no value is associated with it, FALSE will be returned. "
This can be verified in this page:
http://codex.wordpress.org/Function_Reference/get_option
In the description for the funciton get_option

So, the correct if statement is slightly different. I tried this one and it went ok:
if (get_option("fbComments_commentCount_$xid") !== FALSE) {

@rsantiago rsantiago reopened this Apr 30, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants