Skip to:
Content

BuddyPress.org

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's profile imath Owned by: djpaul's profile 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)

6494.patch (998 bytes) - added by imath 10 years ago.
6494.02.patch (998 bytes) - added by imath 9 years ago.
6494.unittest.patch (2.0 KB) - added by imath 9 years ago.
6494.03.patch (899 bytes) - added by r-a-y 9 years ago.
6494.03.unittest.patch (3.1 KB) - added by imath 9 years ago.

Download all attachments as: .zip

Change History (11)

@imath
10 years ago

@imath
9 years ago

@imath
9 years ago

@r-a-y
9 years ago

#1 @r-a-y
9 years ago

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 passes 6494.unittest.patch. Let me know what you think.

#2 @imath
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 @r-a-y
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 @DJPaul
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.

#5 @r-a-y
9 years ago

  • Keywords has-patch commit added; needs-refresh needs-patch removed

02.patch should be committed as it passes the unit tests in 03.unittest.patch.

#6 @djpaul
9 years ago

  • Owner set to djpaul
  • Resolution set to fixed
  • Status changed from new to closed

In 10252:

Blogs: don't duplicate activity comments during post/activity sync

When JS is disabled, when you post an activity comment to a blog post
activity item, two activity comments will be created. This happens
because we are updating the activity item three times, and updating the
post comment twice.

This change unhooks some of the actions during activity->blog sync to
prevent these unnecessary updates and the duplicated activity comment.

Fixes #6494

Props imath, r-a-y

Note: See TracTickets for help on using tickets.