Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable cache maps when "Use Object Cache" is disabled #230

Merged
merged 23 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
03e8fd3
- update testing workflow to test against WPGraphQL 1.14.4 (stop-gap …
jasonbahl Jul 13, 2023
cc31439
- phpcs adjustments
jasonbahl Jul 13, 2023
4f74208
- phpcs adjustments
jasonbahl Jul 13, 2023
af23939
- pinning tests (temp) to WPGraphQL v1.14.5
jasonbahl Jul 13, 2023
3069d92
- fix matrix
jasonbahl Jul 13, 2023
f6d8c9a
- fix build-arg
jasonbahl Jul 13, 2023
1d24009
- update filter name in test
jasonbahl Jul 13, 2023
5a37344
- updating the test matrix to use fail-fast, but exclude failing fast…
jasonbahl Jul 13, 2023
d6ea12f
see: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for…
jasonbahl Jul 13, 2023
c8fca33
see: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for…
jasonbahl Jul 13, 2023
05360f9
no message
jasonbahl Jul 13, 2023
f251360
- update matrix
jasonbahl Jul 13, 2023
396de4f
- set WPGRAPHQL_VERSION back to latest in .env
jasonbahl Jul 13, 2023
e41a350
Change passing WPGRAPHQL_VERSION using -e
markkelnar Jul 14, 2023
a97f17b
docker run command needs -e for variable.
markkelnar Jul 14, 2023
94b1933
Pin to wpgraphql 1.14.4
markkelnar Jul 14, 2023
1c0cc63
Don't put wpgraphql_version in the matrix
markkelnar Jul 14, 2023
6d28a7a
- update matrix to include latest and 1.14.4
jasonbahl Jul 14, 2023
d689adb
- fail-fast: false
jasonbahl Jul 14, 2023
e6298a6
- fail-fast: false
jasonbahl Jul 14, 2023
8c6a988
- update filter names to be `graphql_cache` instead of `wpgraphql_cache`
jasonbahl Jul 14, 2023
0d8dfac
- reverting to filter name `wpgraphql_cache` (see: https://github.com…
jasonbahl Jul 14, 2023
9479e3d
- updating filter name
jasonbahl Jul 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/tests-wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ jobs:
runs-on: ubuntu-latest
name: WordPress ${{ matrix.wordpress }} Integration Tests on PHP ${{ matrix.php }}
strategy:
fail-fast: false
matrix:
php: [ '8.0', '7.4' ]
wordpress: [ '5.9', '5.8', '5.7.2', '5.6' ]
wpgraphql_version: [ 'latest' ]
include:
- php: '8.0'
wordpress: '6.0'
- php: '8.1'
wordpress: '6.1'
# Temporary inclusion while we resolve the tests that broke in the WPGraphQL v1.14.5 release
# this allows us to continue testing new features to this codebase while we work
# toward updating the tests impacted by that release
- php: '8.1'
wordpress: '6.2'
wpgraphql_version: '1.14.4'
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -58,7 +66,7 @@ jobs:
run: composer update

- name: Run acceptance, functional tests
run: docker-compose run -e DEBUG=1 testing
run: docker-compose run -e DEBUG=1 -e WPGRAPHQL_VERSION=${{matrix.wpgraphql_version}} testing
env:
WP_VERSION: ${{ matrix.wordpress }}
PHP_VERSION: ${{ matrix.php }}
Expand Down
23 changes: 22 additions & 1 deletion src/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,29 @@ public static function caching_enabled() {
// get the cache_toggle setting
$option = function_exists( 'get_graphql_setting' ) ? \get_graphql_setting( 'cache_toggle', false, 'graphql_cache_section' ) : false;

$enabled = ( 'on' === $option );

$enabled = apply_filters( 'wpgraphql_cache_wordpress_cache_enabled', (bool) $enabled );
jasonbahl marked this conversation as resolved.
Show resolved Hide resolved

// if there's no user logged in, and GraphQL Caching is enabled
return ( 'on' === $option );
return (bool) $enabled;
}

/**
* Whether cache maps are enabled.
*
* Cache maps are used to track which nodes and list keys are associated with which queries,
* and can be referenced to purge specific queries.
*
* Default behavior is to only enable building and storage of the cache maps if "WordPress Cache" (non-network cache) is enabled, but this can be filtered to be enabled without WordPress cache being enabled.
*
* @return bool
*/
public static function cache_maps_enabled() {

// Whether "WordPress Cache" (object/transient) cache is enabled
$enabled = self::caching_enabled();
return (bool) apply_filters( 'wpgraphql_cache_enable_cache_maps', (bool) $enabled );
jasonbahl marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/Cache/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use GraphQL\Executor\ExecutionResult;
use GraphQL\Type\Schema;
use WPGraphQL\Request;
use WPGraphQL\SmartCache\Admin\Settings;

class Collection extends Query {

Expand Down Expand Up @@ -62,6 +63,12 @@ public function save_query_mapping_cb(
$request,
$query_id
) {

// If cache maps are not enabled, do nothing
if ( ! Settings::cache_maps_enabled() ) {
return;
}

$request_key = $this->build_key( $query_id, $query, $variables, $operation );

// get the runtime nodes from the query analyzer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public function setUp(): void {
*/
$this->clearSchema();

// enable graphql cache maps
add_filter( 'wpgraphql_cache_enable_cache_maps', '__return_true' );

// prevent default category from being added to posts on creation
update_option( 'default_category', 0 );

Expand Down
10 changes: 9 additions & 1 deletion tests/wpunit/CacheCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@

class CacheCollectionTest extends \Codeception\TestCase\WPTestCase {

public function testAddData() {
public function _setUp() {

// enable graphql cache maps
add_filter( 'wpgraphql_cache_enable_cache_maps', '__return_true' );

parent::_setUp(); // TODO: Change the autogenerated stub
}

public function testAddData() {
$key = uniqid( 'test-' );
$content = 'foo-bar';

Expand Down
5 changes: 4 additions & 1 deletion tests/wpunit/CacheFromConnectionFieldNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class CacheFromConnectionFieldNameTest extends \Codeception\TestCase\WPTestCase

public function setUp(): void {
// clear schema so that the register connection works
\WPGraphQL::clear_schema();
// enable graphql cache maps
add_filter( 'wpgraphql_cache_enable_cache_maps', '__return_true' );

\WPGraphQL::clear_schema();
parent::setUp();
}

Expand Down
4 changes: 4 additions & 0 deletions tests/wpunit/CacheInvalidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ class CacheInvalidationTest extends \Codeception\TestCase\WPTestCase {
protected $collection;

public function setUp(): void {

\WPGraphQL::clear_schema();

// enable graphql cache maps
add_filter( 'wpgraphql_cache_enable_cache_maps', '__return_true' );

if ( ! defined( 'GRAPHQL_DEBUG' ) ) {
define( 'GRAPHQL_DEBUG', true );
}
Expand Down
Loading