[wp-hackers] A Basic Activity Feed - Is This Efficient?

J.D. Grimes jdg at codesymphony.co
Tue Oct 29 19:32:29 UTC 2013


Oh, if you want to paginate it, then you will want to look at some tutorials on pagination. You would reload the page or update the page via AJAX, and that request would load the next/previous 10 rows for the user. You can output all rows an paginate them with JS, but depending on the number of rows of activity, that will probably be a waste.

On Oct 29, 2013, at 3:11 PM, Gregory Lancaster <greglancaster71 at gmail.com> wrote:

> oh JD- If I limit the pull to say 10 rows, how would I allow the user to
> pull 10 more at s time?  So show 10 and on click load the next 10 previous,
> etc...
> 
> On Tuesday, October 29, 2013, J.D. Grimes wrote:
> 
>> Any activity feed will require a lot of database queries, and yours
>> probably requires less than BuddyPress’s. I would suggest that you put the
>> limit directly in the SQL query. Right now you are pulling more entries
>> from the DB than you need. So:
>> 
>> $activity_calls = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' .
>> $wpdb->prefix .
>> 'jo_activity_feed WHERE user_id = %d ORDER BY id ASC LIMIT %d',
>> $author_id, $limit ) );
>> 
>> Abdussamad’s solution for the activity message is good. Just FYI, you
>> could also have used a switch statement:
>> 
>>        switch ( $row->activity_type ) {
>> 
>>                case ‘new_record’:
>>                        $message = //…
>>                        $points = //…
>>                break;
>> 
>>                case ‘deleted_record’:
>>                        //...
>>        }
>> 
>> But his solution is better.
>> 
>> -J.D.
>> 
>> On Oct 29, 2013, at 8:34 AM, J.D. Grimes <jdg at codesymphony.co<javascript:;>>
>> wrote:
>> 
>>> This right here is open to sql injection, as Abdussamad pointed out:
>>> 
>>>> $activity_calls = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix .
>>>> 'jo_activity_feed' .' WHERE user_id = '. $author_id .' ORDER BY id
>> ASC');
>>> 
>>> You should be using $wpdb->prepare():
>>> 
>>> $activity_calls = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' .
>> $wpdb->prefix .
>>> 'jo_activity_feed WHERE user_id = %d ORDER BY id ASC', $author_id ) );
>>> 
>>> -J.D.
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com <javascript:;>
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> 
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com <javascript:;>
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list