Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/08/2014 06:55:30 AM (11 years ago)
Author:
imath
Message:

Insert a new "since" filter for the activity stream to be used by HeartBeat check feature

In rare cases, the field date_recorded of the activity table can be updated to a date greater than the most recent activity in terms of id.
The Heartbeat feature was based on the id field so far, while the activity stream is sorting items according to the date_recorded field. As a result, in this very particular case, activities with an id greater than the activity (which date has been updated) will be loaded again in the stream and this until a new activity is published.
To prevent this to happen, we introduce this new "since" filter to be used by the HeartBeat feature once it gets the timestamp of the most recent activity displayed in the stream.

props SGr33n, boonebgorges, imath

Fixes #5505

File:
1 edited

Legend:

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

    r8249 r8251  
    11901190     *
    11911191     * @param array $filter_array {
    1192      *     Fields and values to filter by. Each can be either a single
    1193      *     string, a comma-separated list, or an array of values.
     1192     *     Fields and values to filter by.
    11941193     *     @type array|string|id $user_id User ID(s).
    11951194     *     @type array|string $object Corresponds to the 'component'
     
    12011200     *     @type array|string|int $secondary_id Corresponds to the
    12021201     *           'secondary_item_id' column in the database.
     1202     *     @type int $offset Return only those items with an ID greater
     1203     *           than the offset value.
     1204     *     @type string $since Return only those items that have a
     1205     *           date_recorded value greater than a given MySQL-formatted
     1206     *           date.
    12031207     * }
    12041208     * @return string The filter clause, for use in a SQL query.
     
    12411245            $sid_sql = absint( $filter_array['offset'] );
    12421246            $filter_sql[] = "a.id >= {$sid_sql}";
     1247        }
     1248
     1249        if ( ! empty( $filter_array['since'] ) ) {
     1250            // Validate that this is a proper Y-m-d H:i:s date
     1251            // Trick: parse to UNIX date then translate back
     1252            $translated_date = date( 'Y-m-d H:i:s', strtotime( $filter_array['since'] ) );
     1253            if ( $translated_date === $filter_array['since'] ) {
     1254                $filter_sql[] = "a.date_recorded > '{$translated_date}'";
     1255            }
    12431256        }
    12441257
Note: See TracChangeset for help on using the changeset viewer.