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

Gregory Lancaster greglancaster71 at gmail.com
Tue Oct 29 19:11:18 UTC 2013


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
>


More information about the wp-hackers mailing list