AnsPress_Admin_Ajax::recount_flags( integer $current, integer $offset )

Description #

Recount flags of posts.

Parameters #

  • $current
    integer (Required) Current index.
  • $offset
    integer (Required) Current offset.

Changelog #

VersionDescription
4.0.5Introduced.

Source #

File: admin/ajax.php

	public static function recount_flags( $current, $offset ) {
		global $wpdb;

		$ids = $wpdb->get_col( "SELECT SQL_CALC_FOUND_ROWS ID FROM {$wpdb->posts} WHERE post_type IN ('question', 'answer') LIMIT {$offset},50" ); // @codingStandardsIgnoreLine.

		$total_found = $wpdb->get_var( 'SELECT FOUND_ROWS()' ); // DB call okay, Db cache okay.

		foreach ( (array) $ids as $id ) {
			ap_update_flags_count( $id );
		}

		$action = 'continue';

		if ( count( $ids ) < 50 ) {
			$action = 'success';
		}

		wp_send_json( [
			'action'    => $action,
			'total'     => $total_found,
			'processed' => count( $ids ),
		] );
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment