Skip to:
Content

BuddyPress.org

Changeset 8226


Ignore:
Timestamp:
04/01/2014 12:28:34 AM (10 years ago)
Author:
boonebgorges
Message:

Better checks for existence of parent item when recursing to calculate activity comment depth

The changes introduced in r8201 involve calculating tree depth for each queried
activity comment in a loop. The technique used involves traversing up a tree by
fetching the parent item until the root level is reached. However, the original
technique did not account for the fact that in certain cases - namely, when
display_comments=threaded - it may not be the case that all of the comment
ancestors are available in the current query. This failed logic resulted in
infinite regression in these sorts of cases.

The correction involves performing a separate query for the direct activity
parent when it is not found in the queried items.

Props r-a-y

Fixes #2768

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r8201 r8226  
    10141014                while ( $parent_id !== $r->item_id ) {
    10151015                    $depth++;
    1016                     $parent_id = $ref[ $parent_id ]->secondary_item_id;
     1016
     1017                    // When display_comments=stream, the
     1018                    // parent comment may not be part of
     1019                    // the returned results, so we manually
     1020                    // fetch it
     1021                    if ( empty( $ref[ $parent_id ] ) ) {
     1022                        $direct_parent = new BP_Activity_Activity( $parent_id );
     1023                        if ( isset( $direct_parent->secondary_item_id ) ) {
     1024                            $parent_id = $direct_parent->secondary_item_id;
     1025                        } else {
     1026                            // Something went wrong
     1027                            // Short-circuit the
     1028                            // depth calculation
     1029                            $parent_id = $r->item_id;
     1030                        }
     1031                    } else {
     1032                        $parent_id = $ref[ $parent_id ]->secondary_item_id;
     1033                    }
    10171034                }
    10181035                $r->depth = $depth;
Note: See TracChangeset for help on using the changeset viewer.