Skip to content

Commit b176bd5

Browse files
committed
Merge branch 'main' into fix-logging-plugin-ui
2 parents 8266ec9 + 6fd39e3 commit b176bd5

File tree

19 files changed

+550
-56
lines changed

19 files changed

+550
-56
lines changed

.changeset/popular-carrots-impress.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

plugins/composer-packages.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,58 @@
423423
}
424424
},
425425
"wpengine/wpgraphql-logging": {
426+
"0.2.1": {
427+
"name": "wpengine/wpgraphql-logging",
428+
"version": "0.2.1",
429+
"type": "wordpress-plugin",
430+
"description": "A plugin for logging WPGraphQL request lifecycle tp help with debugging and performance analysis for WPGraphQL queries.",
431+
"homepage": "https://github.com/wpengine/hwptoolkit",
432+
"license": "GPL-2.0",
433+
"authors": [
434+
{
435+
"name": "WP Engine Headless OSS Development Team",
436+
"email": "headless-oss@wpengine.com",
437+
"homepage": "https://wpengine.com/"
438+
}
439+
],
440+
"support": {
441+
"issues": "https://github.com/wpengine/hwptoolkit/issues",
442+
"email": "support@wpengine.com"
443+
},
444+
"dist": {
445+
"url": "https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-logging-wordpress-plugin-0.2.1/wpgraphql-logging.zip",
446+
"type": "zip"
447+
},
448+
"require": {
449+
"composer/installers": "~1.0 || ~2.0"
450+
}
451+
},
452+
"0.2.0": {
453+
"name": "wpengine/wpgraphql-logging",
454+
"version": "0.2.0",
455+
"type": "wordpress-plugin",
456+
"description": "A plugin for logging WPGraphQL request lifecycle tp help with debugging and performance analysis for WPGraphQL queries.",
457+
"homepage": "https://github.com/wpengine/hwptoolkit",
458+
"license": "GPL-2.0",
459+
"authors": [
460+
{
461+
"name": "WP Engine Headless OSS Development Team",
462+
"email": "headless-oss@wpengine.com",
463+
"homepage": "https://wpengine.com/"
464+
}
465+
],
466+
"support": {
467+
"issues": "https://github.com/wpengine/hwptoolkit/issues",
468+
"email": "support@wpengine.com"
469+
},
470+
"dist": {
471+
"url": "https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-logging-wordpress-plugin-0.2.0/wpgraphql-logging.zip",
472+
"type": "zip"
473+
},
474+
"require": {
475+
"composer/installers": "~1.0 || ~2.0"
476+
}
477+
},
426478
"0.1.0": {
427479
"name": "wpengine/wpgraphql-logging",
428480
"version": "0.1.0",

plugins/wpgraphql-logging/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# WPGraphQL Logging
22

3+
## 0.2.1
4+
5+
### Patch Changes
6+
7+
- [#476](https://github.com/wpengine/hwptoolkit/pull/476) [`8156902`](https://github.com/wpengine/hwptoolkit/commit/8156902a1f4cc9dae655129abb788056bf9f76cc) Thanks [@colinmurphy](https://github.com/colinmurphy)! - chore: Add default configuration on plugin activation if no configuration already exists.
8+
9+
## 0.2.0
10+
11+
### Minor Changes
12+
13+
- [#456](https://github.com/wpengine/hwptoolkit/pull/456) [`389a324`](https://github.com/wpengine/hwptoolkit/commit/389a32440d21a9dbfee18dac39e695af6aa0816e) Thanks [@theodesp](https://github.com/theodesp)! - chore: Various improvement to the logging plugin:
14+
15+
- Implemented BufferHandler to batch write database entries for performance
16+
- Implemented LogStoreService to remove hard dependencies of the Database services in the admin and various classes
17+
- Refactored Database and CRUD log services to use interfaces to make it easy to be exctended for other data storage solutions.
18+
- Added missing indexes for performance
19+
- Added filters for caching configuration
20+
- Better error handling
21+
- Added missing nonce for admin pages
22+
323
## 0.1.0
424

525
### Minor Changes

plugins/wpgraphql-logging/bin/run-codeception.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ run_tests() {
6969
# Prefer XML summary for robustness; fallback to HTML if present
7070
if [[ -f "tests/_output/coverage.xml" ]]; then
7171
# Extract total statements and covered statements from the summary metrics line
72-
total_statements=$(grep -Eo 'statements="[0-9]+"' "tests/_output/coverage.xml" | head -1 | grep -Eo '[0-9]+')
73-
total_covered=$(grep -Eo 'coveredstatements="[0-9]+"' "tests/_output/coverage.xml" | head -1 | grep -Eo '[0-9]+')
72+
total_statements=$(grep -Eo ' statements="[0-9]+"' "tests/_output/coverage.xml" | tail -1 | grep -Eo '[0-9]+')
73+
total_covered=$(grep -Eo ' coveredstatements="[0-9]+"' "tests/_output/coverage.xml" | tail -1 | grep -Eo '[0-9]+')
7474
if [[ -n "$total_statements" && -n "$total_covered" && "$total_statements" -gt 0 ]]; then
7575
coverage_percent=$(awk "BEGIN { printf \"%.2f\", ($total_covered / $total_statements) * 100 }")
7676
fi

plugins/wpgraphql-logging/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "wordpress-plugin",
44
"description": "A plugin for logging WPGraphQL request lifecycle tp help with debugging and performance analysis for WPGraphQL queries.",
55
"license": "GPLv2 or later",
6-
"version": "0.1.0",
6+
"version": "0.2.1",
77
"authors": [
88
{
99
"name": "WP Engine Headless OSS Development Team",

plugins/wpgraphql-logging/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wpengine/wpgraphql-logging-wordpress-plugin",
3-
"version": "0.1.0",
3+
"version": "0.2.1",
44
"private": true,
55
"description": "A POC plugin for logging WPGraphQL queries.",
66
"scripts": {

plugins/wpgraphql-logging/phpcs.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@
5454
<rule ref="PSR12.Files.DeclareStatement"/>
5555
<rule ref="PEAR.NamingConventions.ValidClassName"/>
5656
<rule ref="PHPCompatibilityWP"/>
57-
<rule ref="WordPress-VIP-Go"/>
57+
<rule ref="WordPress-VIP-Go">
58+
<exclude name="WordPressVIPMinimum.JS.Window"/>
59+
<exclude name="WordPressVIPMinimum.JS.DangerouslySetInnerHTML"/>
60+
<exclude name="WordPressVIPMinimum.JS.InnerHTML"/>
61+
<exclude name="WordPressVIPMinimum.JS.StrippingTags"/>
62+
<exclude name="WordPressVIPMinimum.JS.StringConcat"/>
63+
<exclude name="WordPressVIPMinimum.JS.HTMLExecutingFunctions"/>
64+
</rule>
5865

5966
<rule ref="WordPress">
6067
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>

plugins/wpgraphql-logging/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Requires at least: 6.5
55
Tested up to: 6.8.2
66
Requires PHP: 8.1.2
77
Requires WPGraphQL: 2.3.0
8-
Stable tag: 0.1.0
8+
Stable tag: 0.2.1
99
License: GPL-2.0-or-later
1010
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1111

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WPGraphQL\Logging\Admin;
6+
7+
/**
8+
* The admin notice class for WPGraphQL Logging.
9+
*
10+
* @package WPGraphQL\Logging
11+
*
12+
* @since 0.0.1
13+
*/
14+
class AdminNotice {
15+
/**
16+
* The admin page slug.
17+
*
18+
* @var string
19+
*/
20+
public const ADMIN_NOTICE_KEY = 'wpgraphql-logging-admin-notice';
21+
22+
/**
23+
* The instance of the admin notice.
24+
*
25+
* @var self|null
26+
*/
27+
protected static ?self $instance = null;
28+
29+
/**
30+
* Initializes the view logs page.
31+
*/
32+
public static function init(): ?self {
33+
if ( ! current_user_can( 'manage_options' ) ) {
34+
return null;
35+
}
36+
37+
if ( ! isset( self::$instance ) || ! ( is_a( self::$instance, self::class ) ) ) {
38+
self::$instance = new self();
39+
self::$instance->setup();
40+
}
41+
42+
do_action( 'wpgraphql_logging_admin_notice_init', self::$instance );
43+
44+
return self::$instance;
45+
}
46+
47+
/**
48+
* Setup the admin notice.
49+
*/
50+
public function setup(): void {
51+
$key = self::ADMIN_NOTICE_KEY;
52+
$is_dismissed = $this->is_notice_dismissed();
53+
54+
// Exit if the notice has been dismissed.
55+
if ( $is_dismissed ) {
56+
return;
57+
}
58+
59+
add_action( 'admin_notices', [ $this, 'register_admin_notice' ], 10, 0 );
60+
add_action( 'wp_ajax_' . $key, [ $this, 'process_ajax_request' ], 10, 0 );
61+
}
62+
63+
/**
64+
* Register admin notice to inform users about WPGraphQL Logging.
65+
*/
66+
public function register_admin_notice(): void {
67+
$template = __DIR__ . '/View/Templates/WPGraphQLLoggerNotice.php';
68+
69+
if ( ! file_exists( $template ) ) {
70+
return;
71+
}
72+
73+
require $template; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
74+
}
75+
76+
/**
77+
* Process the AJAX request.
78+
*/
79+
public function process_ajax_request(): void {
80+
$key = self::ADMIN_NOTICE_KEY;
81+
if ( ! isset( $_POST['action'] ) || esc_attr( $key ) !== $_POST['action'] ) {
82+
return;
83+
}
84+
85+
check_ajax_referer( $key );
86+
87+
self::dismiss_admin_notice();
88+
}
89+
90+
/**
91+
* Check if the admin notice is dismissed.
92+
*/
93+
public function is_notice_dismissed(): bool {
94+
$key = self::ADMIN_NOTICE_KEY;
95+
return (bool) get_user_meta( get_current_user_id(), $key, true );
96+
}
97+
98+
/**
99+
* Dismiss the admin notice.
100+
*/
101+
public static function dismiss_admin_notice(): void {
102+
$key = self::ADMIN_NOTICE_KEY;
103+
update_user_meta( get_current_user_id(), $key, 1 );
104+
}
105+
}

plugins/wpgraphql-logging/src/Admin/Settings/ConfigurationHelper.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ public function clear_cache(): void {
139139
* Get the option key for the settings.
140140
*/
141141
public function get_option_key(): string {
142-
return (string) apply_filters( 'wpgraphql_logging_settings_key', WPGRAPHQL_LOGGING_SETTINGS_KEY );
142+
return WPGRAPHQL_LOGGING_SETTINGS_KEY;
143143
}
144144

145145
/**
146146
* Get the settings group for caching.
147147
*/
148148
public function get_settings_group(): string {
149-
return (string) apply_filters( 'wpgraphql_logging_settings_group_settings_group', WPGRAPHQL_LOGGING_SETTINGS_GROUP );
149+
return WPGRAPHQL_LOGGING_SETTINGS_GROUP;
150150
}
151151

152152
/**
@@ -185,21 +185,26 @@ protected function load_config(): void {
185185

186186
$cache_duration = (int) apply_filters( 'wpgraphql_logging_config_cache_duration', self::CACHE_DURATION );
187187

188+
// Try to get from wp_cache first (in-memory cache).
188189
$cached_config = wp_cache_get( $option_key, self::CACHE_GROUP );
189190
if ( is_array( $cached_config ) ) {
190191
$this->config = $cached_config;
191192
return;
192193
}
193194

195+
// Try to get from the WordPress object cache (could be Redis, Memcached, etc.).
194196
$cached_config = wp_cache_get( $option_key, $this->get_settings_group() );
195197
if ( is_array( $cached_config ) ) {
196198
$this->config = $cached_config;
199+
// Store in our custom cache group for faster access next time.
197200
wp_cache_set( $option_key, $cached_config, self::CACHE_GROUP, $cache_duration );
198201
return;
199202
}
200203

204+
// Load from database.
201205
$this->config = $this->get_option_value( $option_key, [] );
202206

207+
// Cache the result in both cache groups.
203208
wp_cache_set( $option_key, $this->config, self::CACHE_GROUP, $cache_duration );
204209
wp_cache_set( $option_key, $this->config, $this->get_settings_group(), $cache_duration );
205210
}

0 commit comments

Comments
 (0)