Only send new Ticks on AJAX update
THis reduces the overhead of re-sending huge amounts of HTML code to the frontend without any new data to display.
This commit is contained in:
parent
5158b8fdb7
commit
de347e1f81
@ -179,8 +179,9 @@ class WPLiveticker2 {
|
|||||||
$output = '<ul class="wplt2-ticker';
|
$output = '<ul class="wplt2-ticker';
|
||||||
if ( 1 === self::$_options['enable_ajax'] ) {
|
if ( 1 === self::$_options['enable_ajax'] ) {
|
||||||
$output .= ' wplt2-ticker-ajax" '
|
$output .= ' wplt2-ticker-ajax" '
|
||||||
. 'data-wplt2-ticker="' . $atts['ticker'] . '" '
|
. 'data-wplt2-ticker="' . $atts['ticker'] . '" '
|
||||||
. 'data-wplt2-limit="' . $atts['limit'];
|
. 'data-wplt2-limit="' . $atts['limit'] . '" '
|
||||||
|
. 'data-wplt2-last="' . time();
|
||||||
}
|
}
|
||||||
$output .= '">';
|
$output .= '">';
|
||||||
|
|
||||||
@ -266,8 +267,8 @@ class WPLiveticker2 {
|
|||||||
$res = array();
|
$res = array();
|
||||||
foreach ( wp_unslash( $_POST['update'] ) as $update_req ) {
|
foreach ( wp_unslash( $_POST['update'] ) as $update_req ) {
|
||||||
if ( isset( $update_req['s'] ) ) {
|
if ( isset( $update_req['s'] ) ) {
|
||||||
$slug = $update_req['s'];
|
$slug = $update_req['s'];
|
||||||
$limit = ( isset( $update_req['l'] ) ) ? intval( $update_req['l'] ) : - 1;
|
$limit = ( isset( $update_req['l'] ) ) ? intval( $update_req['l'] ) : - 1;
|
||||||
$last_poll = ( isset( $update_req['t'] ) ) ? intval( $update_req['t'] ) : 0;
|
$last_poll = ( isset( $update_req['t'] ) ) ? intval( $update_req['t'] ) : 0;
|
||||||
|
|
||||||
// Query new ticks from DB.
|
// Query new ticks from DB.
|
||||||
@ -281,6 +282,9 @@ class WPLiveticker2 {
|
|||||||
'terms' => $slug,
|
'terms' => $slug,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
'date_query' => array(
|
||||||
|
'after' => date( 'c', $last_poll ),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new WP_Query( $query_args );
|
$query = new WP_Query( $query_args );
|
||||||
|
@ -42,9 +42,14 @@ WPLT2.update = function () {
|
|||||||
jQuery.each(update, function (i, u) {
|
jQuery.each(update, function (i, u) {
|
||||||
jQuery.each(WPLT2.ticker, function (j, t) {
|
jQuery.each(WPLT2.ticker, function (j, t) {
|
||||||
if (t.s === u.s) {
|
if (t.s === u.s) {
|
||||||
// Set HTML content.
|
// Prepend HTML of new ticks.
|
||||||
jQuery(t.e).html(u.h);
|
jQuery(t.e).prepend(u.h);
|
||||||
// Set last poll timestamp.
|
// Remove tail, if limit is set.
|
||||||
|
const l = jQuery(t.e).data('wplt2Limit');
|
||||||
|
if (l > 0) {
|
||||||
|
jQuery(t.e).find('li').slice(l).remove();
|
||||||
|
}
|
||||||
|
// Update last poll timestamp.
|
||||||
jQuery(t.e).data('wplt2Last', u.t);
|
jQuery(t.e).data('wplt2Last', u.t);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user