collector->get_data(); if ( empty( $data->dupes ) ) { return; } $this->before_tabular_output(); echo ''; echo ''; echo '' . esc_html__( 'Query', 'query-monitor' ) . ''; echo '' . esc_html__( 'Count', 'query-monitor' ) . ''; echo '' . esc_html__( 'Time', 'query-monitor' ) . ''; echo '' . esc_html__( 'Callers', 'query-monitor' ) . ''; if ( ! empty( $data->dupe_components ) ) { echo '' . esc_html__( 'Components', 'query-monitor' ) . ''; } echo '' . esc_html__( 'Potential Troublemakers', 'query-monitor' ) . ''; echo ''; echo ''; echo ''; /* translators: %s: Number of calls to a PHP function */ $call_text = _n_noop( '%s call', '%s calls', 'query-monitor' ); foreach ( $data->dupes as $sql => $queries ) { // This should probably happen in the collector's processor $type = QM_Util::get_query_type( $sql ); $sql_out = self::format_sql( $sql ); $time = $data->dupe_times[ $sql ]; if ( 'SELECT' !== $type ) { $sql_out = "{$sql_out}"; } echo ''; echo ''; echo $sql_out; // WPCS: XSS ok; echo ''; echo ''; echo esc_html( number_format_i18n( count( $queries ), 0 ) ); echo ''; echo ''; echo esc_html( number_format_i18n( $time, 4 ) ); echo ''; echo ''; foreach ( $data->dupe_callers[ $sql ] as $caller => $calls ) { echo self::build_filter_trigger( 'db_queries', 'caller', $caller, '' . esc_html( $caller ) . '' ); // WPCS: XSS ok; printf( '
%s
', esc_html( sprintf( translate_nooped_plural( $call_text, $calls, 'query-monitor' ), number_format_i18n( $calls ) ) ) ); } echo ''; if ( isset( $data->dupe_components[ $sql ] ) ) { echo ''; foreach ( $data->dupe_components[ $sql ] as $component => $calls ) { printf( '%s
%s
', esc_html( $component ), esc_html( sprintf( translate_nooped_plural( $call_text, $calls, 'query-monitor' ), number_format_i18n( $calls ) ) ) ); } echo ''; } echo ''; foreach ( $data->dupe_sources[ $sql ] as $source => $calls ) { printf( '%s
%s
', esc_html( $source ), esc_html( sprintf( translate_nooped_plural( $call_text, $calls, 'query-monitor' ), number_format_i18n( $calls ) ) ) ); } echo ''; echo ''; } echo ''; $this->after_tabular_output(); } /** * @param array $menu * @return array */ public function admin_menu( array $menu ) { /** @var QM_Collector_DB_Dupes|null $dbq */ $dbq = QM_Collectors::get( 'db_dupes' ); if ( $dbq ) { /** @var QM_Data_DB_Queries $dbq_data */ $dbq_data = $dbq->get_data(); if ( ! empty( $dbq_data->dupes ) ) { $count = 0; foreach ( $dbq_data->dupes as $dupe ) { $count += count( $dupe ); } $menu[ $this->collector->id() ] = $this->menu( array( 'title' => esc_html( sprintf( /* translators: %s: Number of duplicate database queries */ __( 'Duplicate Queries (%s)', 'query-monitor' ), number_format_i18n( $count ) ) ), ) ); } } return $menu; } /** * @param array $menu * @return array */ public function panel_menu( array $menu ) { $id = $this->collector->id(); if ( isset( $menu[ $id ] ) ) { $menu['qm-db_queries']['children'][] = $menu[ $id ]; unset( $menu[ $id ] ); } return $menu; } } /** * @param array $output * @param QM_Collectors $collectors * @return array */ function register_qm_output_html_db_dupes( array $output, QM_Collectors $collectors ) { $collector = QM_Collectors::get( 'db_dupes' ); if ( $collector ) { $output['db_dupes'] = new QM_Output_Html_DB_Dupes( $collector ); } return $output; } add_filter( 'qm/outputter/html', 'register_qm_output_html_db_dupes', 45, 2 );