Opened 10 years ago
Closed 9 years ago
#6494 closed defect (bug) (fixed)
Duplicate activity comments when post/activity comments sync is on
Reported by: | imath | Owned by: | djpaul |
---|---|---|---|
Milestone: | 2.4 | Priority: | normal |
Severity: | normal | Version: | 2.0 |
Component: | Blogs | Keywords: | has-patch commit |
Cc: |
Description
While working on #6482, and thanks to shanebp's tests it appears that when javascript is disabled (you can simulate this by doing define( SCRIPT_DEBUG, false )
), when you post an activity comment to a blog post activity, two activity comments will be created.
It doesn't happen when javascript is enabled, because instead of being created twice, the activity comment is updated. Reason is Ajax is using an action post variable so we arrive here https://buddypress.trac.wordpress.org/browser/trunk/src/bp-blogs/bp-blogs-functions.php#L646
This means when an activity comment is posted :
- a post comment is created
- the activity is immediatly resaved to build the WP comment permalink
- then the post comment is updated
- then the activity is updated.
We are saving the activity three times and the post comment twice. I suggest the attached patch to only save these items respectively twice and once (i.e. : what we really need)
Attachments (5)
Change History (11)
#2
@
9 years ago
- Keywords dev-feedback added
Thanks for your feedback r-a-y and it's my turn to apologize for this late reply :)
I think removing the $_REQUEST['action'] is half fixing the problem. I've updated the unit test (see 6494.03.unittest.patch) to try to show what the "full" problem is.
I think if this check was added, it was to be sure a comment was being edited within the WP Admin (Ajax or not). WordPress is only using wp_update_comment()
once when edit_comment()
is used.
If we remove the check, i agree that the unit tests is showing that no duplicate activity comments will be created, but this activity will be saved 3 times and the comment will be saved twice. And i think for both objects it's one time too much. We should avoid this one time too much.
Activity should be saved twice and the comment once.
About activity, why twice? Because it's first saved here https://buddypress.trac.wordpress.org/browser/trunk/src/bp-activity/bp-activity-functions.php#L2148 and then as it's synced with a post comment, we need to update its primary link here: https://buddypress.trac.wordpress.org/browser/trunk/src/bp-blogs/bp-blogs-activity.php#L607
so i think it's best to make sure an activity won't be edited right away after being posted by doing remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
in bp_blogs_sync_add_from_activity_comment()
like i've suggested in .02.patch.
What do you think ?
#3
@
9 years ago
- Keywords commit added
You are absolutely right, imath!
Thanks for updating the unit test to show the number of times the activity item was being saved.
#4
@
9 years ago
- Keywords needs-refresh needs-patch added; has-patch dev-feedback commit removed
The tests in 6494.03.unittest.patch are not passing when 6494.03.patch is applied, so we need to take another look at this.
Apologies for the late reply to this, imath.
About $_REQUEST['action'], you are absolutely right.
I think we can simply get rid of the
$_REQUEST['action']
check and this will also solve the problem.03.patch
does this; it also passes6494.unittest.patch
. Let me know what you think.