Fixing double posts counts for users with linked accounts - #567
Merged
sboisvert merged 1 commit intoJul 17, 2018
Merged
Conversation
cap- prefixed term when counting user posts.
Contributor
|
This is an awesome Fix and an awesome explanation of the fix! |
Contributor
rebeccahum
pushed a commit
that referenced
this pull request
Mar 26, 2019
…t-authors Fixing double posts counts for users with linked accounts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes #561.
On a correct, up-to-date CAP installation, posts counts for authors with guest authors profile are absolutely off - basically, they are double what they should.
This is an example with CAP enabled - clearly off since the

Mineposts is more than the total:With CAP disabled:

Prior to this PR, the code which filtered the WP posts count was this:
Both
$termand$guest_termare considered, guessing that$termwould hold the non-prefixed version of the CAP author term, while$guest_termthe prefixedcap-one. The counts are later summed under the assumption that they are complementary. The flaw is that$this->get_author_term()already fetches the one term that exists, giving priority to the prefixedcap-version of it. So what happens is that, ifcap-$usernameexists, both$termand$guest_termwill contain its content, and$countwill then be doubled.The fix is thus to get rid of the
$guest_termvar and only retain the final conditional:But aren't we losing some counts on the way? Aren't we discarding the non-prefixed version of the term? Is it just useless? No, we don't lose counts; No, we are discarding it, and no, it is not useless. The pivot is
$this->update_author_term(): it will update any of the terms that exist, also suggesting that it should never happen that they co-exist: either there is the prefixedcap-term, or the non-prefixed one. In any case,get_author_term()will fetch the one that exists for the author, which will already contain the total count, and we don't need to sum anything to it.(I think we should also think about migrating terms to all having the
cap-prefix, but this is another issue #566)