[buddypress-trac] [BuddyPress Trac] #6865: `bp_activity_get_actions()` should only sort when necessary

buddypress-trac noreply at wordpress.org
Wed Feb 3 04:29:20 UTC 2016


#6865: `bp_activity_get_actions()` should only sort when necessary
----------------------------------------+------------------
 Reporter:  boonebgorges                |       Owner:
     Type:  enhancement                 |      Status:  new
 Priority:  normal                      |   Milestone:  2.5
Component:  Component - Activity        |     Version:
 Severity:  normal                      |  Resolution:
 Keywords:  has-patch needs-unit-tests  |
----------------------------------------+------------------

Comment (by boonebgorges):

 Replying to [comment:3 imath]:
 > My first thought is i agree saving overload is very important, but i
 think we must be careful to make sure things are still working the way
 they should :)

 Details, details ;)

 I'm not sure why your approach in [attachment:6865.02.patch] works, but I
 guess my original patch didn't work because of the loose comparison of
 objects. A simple flag like `$do_sort` in [attachment:6865.2.diff] works
 better, and is probably easier to understand.

 In my testing, the initial call to `bp_activity_set_actions()` always
 sorts *unless there are no post types being tracked in the activity
 stream*. For this reason, I added a second flag: `$sorted`. I'm not sure
 what a unit test for this would look like - we can wipe the
 `$bp->activity->actions` object and reinitialize it, but we'll need to
 shut down post type tracking temporarily in order to trigger the scenario
 in which `$sorted` is necessary.

 In a quick test where I called `bp_activity_get_actions()` about 500
 times, wall time for the function is 1.33 seconds before the patch, and
 .194 seconds with the patch. (And much faster still with the changes to
 `bp_sort_by_key()` suggested in #6864.)

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6865#comment:4>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list