imath / bp-reshare

BuddyPress component to reshare activities
33 stars 16 forks source link

activity id in buddyreshare_activity_can_reshare() #16

Closed KristianI closed 7 years ago

KristianI commented 8 years ago

Hello

Thanks for a great plugin.

All my reshared posts had a delay of about 2-3 seconds, and was dragging my page performance down.

I tracked it down to buddyreshare_activity_can_reshare(). When calling the function an activity_id of 0 was passed in the parameters, which caused bp_activity_get() to hang.

The activity id of 0 was returned by the buddyreshare_activity_get_id_to_reshare()-function.

I fixed this issue by adding "&& $activity_id !== 0" in buddyreshare_activity_can_reshare(), like this:

function buddyreshare_activity_can_reshare( $activity_id = null ) {
    global $activities_template;

        if ( ! is_null( $activity_id ) && $activity_id !== 0 ) {
            $activities = bp_activity_get( array( 'in' => $activity_id ) );
            $activity = $activities['activities'][0];
        } else {
            $activity = $activities_template->activity;
        }

        $can_reshare = buddyreshare_can_reshare( $activity );

    return apply_filters( 'buddyreshare_activity_can_reshare', (bool) $can_reshare );
}

@imath , if you approve of this fix I would be happy to make a pull request.

Best regards Kristian

imath commented 8 years ago

Hi Kristian,

thanks for your contribution. What about simply using ! empty( $activity_id ) ?

Sure you can do the pull request, i'll be happy to merge it ;)

imath. http://profiles.wordpress.org/imath/

Le 28 janv. 2016 à 06:40, Kristian Iversen notifications@github.com a écrit :

Hello

Thanks for a great plugin.

All my reshared posts had a delay of about 2-3 seconds, and was dragging my page performance down.

I tracked it down to buddyreshare_activity_can_reshare(). When calling the function an activity_id of 0 was passed in the parameters, which caused bp_activity_get() to hang.

The activity id of 0 was returned by the buddyreshare_activity_get_id_to_reshare()-function.

I fixed this issue by adding "&& $activity_id !== 0" in buddyreshare_activity_can_reshare(), like this:

function buddyreshare_activity_can_reshare( $activity_id = null ) { global $activities_template;

if ( ! is_null( $activity_id ) && $activity_id !== 0 ) {
    $activities = bp_activity_get( array( 'in' => $activity_id ) );
    $activity = $activities['activities'][0];
} else {
    $activity = $activities_template->activity;
}

$can_reshare = buddyreshare_can_reshare( $activity );

return apply_filters( 'buddyreshare_activity_can_reshare', (bool) $can_reshare ); }

@imath , if you approve of this fix I would be happy to make a pull request.

Best regards Kristian

— Reply to this email directly or view it on GitHub.

imath commented 7 years ago

Well seems this function has changed a bit, i can't find this part of the code anymore.