Skip to content

Commit

Permalink
snake case function name
Browse files Browse the repository at this point in the history
text description change.
  • Loading branch information
markkelnar committed Jul 24, 2023
1 parent 614a874 commit 037df6e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
"wp-graphql/wp-graphql-testcase": "*",
"squizlabs/php_codesniffer": "^3.6",
"phpcompatibility/phpcompatibility-wp": "*",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"wp-coding-standards/wpcs": "^2.3",
"lucatume/wp-browser": "^3.0",
"codeception/module-asserts": "^1.3",
"codeception/module-asserts": "^1.3.1",
"codeception/module-phpbrowser": "^1.0",
"codeception/module-webdriver": "^1.2",
"codeception/module-db": "^1.1",
Expand Down Expand Up @@ -65,10 +64,7 @@
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
},
"require": {
"appsero/client": "^1.2"
}
Expand Down
1 change: 0 additions & 1 deletion src/Admin/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use WPGraphQL\SmartCache\Document;
use WPGraphQL\SmartCache\Document\Grant;
use WPGraphQL\SmartCache\Document\MaxAge;
use WPGraphQL\SmartCache\Document\GarbageCollection;
use GraphQL\Error\SyntaxError;
use GraphQL\Server\RequestError;

Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function () {
[
'name' => 'query_garbage_collect',
'label' => __( 'Delete Old Queries', 'wp-graphql-smart-cache' ),
'desc' => __( 'Toggle on to enable garbage collection (delete) of saved queries older than number of days specified below. Queries that are part of a "Group" will be excluded from garbage collection.', 'wp-graphql-smart-cache' ),
'desc' => __( 'Toggle on to enable garbage collection (delete) of saved queries older than number of days specified below. Queries that are tagged in a "Group" will be excluded from garbage collection.', 'wp-graphql-smart-cache' ),
'type' => 'checkbox',
'default' => 'off',
'sanitize_callback' => function ( $value ) {
Expand Down
4 changes: 2 additions & 2 deletions src/Document/GarbageCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class GarbageCollection {
*
* @return [int] Array of post ids
*/
public static function getDocumentsByAge( $number_of_posts = 100 ) {
public static function get_documents_by_age( $number_of_posts = 100 ) {
// $days_ago Posts older than this many days ago
$days_ago = get_graphql_setting( 'query_gc_age', null, 'graphql_persisted_queries_section' );
$days_ago = get_graphql_setting( 'garbage_collect_age', null, 'graphql_persisted_queries_section' );
if ( 1 > $days_ago || ! is_numeric( $days_ago ) ) {
return [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Document/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function init() {
'show_ui' => Settings::show_in_admin(),
'show_in_quick_edit' => false,
'show_in_graphql' => true,
'graphql_single_name' => 'graphql_document_group',
'graphql_plural_name' => 'graphql_document_groups',
'graphql_single_name' => 'graphqlDocumentGroup',
'graphql_plural_name' => 'graphqlDocumentGroups',
]
);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/wpunit/DocumentGarbageCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public function testQueriesAreDeletedByJob() {

// Check number of posts we would delete older than 10 days.
$this->updateAge( 10 );
$this->assertCount( 6, GarbageCollection::getDocumentsByAge() );
$this->assertCount( 6, GarbageCollection::get_documents_by_age() );

// Check number of posts we would delete older than 20 days.
$this->updateAge( 20 );
$this->assertCount( 3, GarbageCollection::getDocumentsByAge() );
$this->assertCount( 3, GarbageCollection::get_documents_by_age() );

// Verify delete event is not scheduled before the garbage collection event runs
$this->assertFalse( wp_next_scheduled( 'wpgraphql_smart_cache_query_garbage_collect_deletes' ) );
Expand All @@ -98,14 +98,14 @@ public function testQueriesAreDeletedByJob() {

// Fire the delete action and verify the number of posts deleted
do_action( 'wpgraphql_smart_cache_query_garbage_collect_deletes' );
$this->assertCount( 1, GarbageCollection::getDocumentsByAge() );
$this->assertCount( 1, GarbageCollection::get_documents_by_age() );

// Fire the delete action again, verify expected queries are removed.
do_action( 'wpgraphql_smart_cache_query_garbage_collect_deletes' );
$this->updateAge( 10 );
$this->assertCount( 3, GarbageCollection::getDocumentsByAge() );
$this->assertCount( 3, GarbageCollection::get_documents_by_age() );
$this->updateAge( 20 );
$this->assertCount( 0, GarbageCollection::getDocumentsByAge( 20 ) );
$this->assertCount( 0, GarbageCollection::get_documents_by_age( 20 ) );
}

}
6 changes: 3 additions & 3 deletions wp-graphql-smart-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function () {
}

// If more posts exist to remove, schedule the removal event
$posts = GarbageCollection::getDocumentsByAge( 1 );
$posts = GarbageCollection::get_documents_by_age( 1 );
if ( $posts ) {
wp_schedule_single_event( time() + 1, 'wpgraphql_smart_cache_query_garbage_collect_deletes' );
}
Expand All @@ -314,14 +314,14 @@ function () {
function () {
// If posts exist to remove, schedule the removal event
$batch_size = apply_filters( 'wpgraphql_document_garbage_collection_batch_size', 1000 );
$posts = GarbageCollection::getDocumentsByAge( $batch_size );
$posts = GarbageCollection::get_documents_by_age( $batch_size );
foreach ( $posts as $post_id ) {
// Check if the post is selected to skip garbage collection
wp_delete_post( $post_id );
}

// If more posts exist to remove, schedule the removal event
$posts = GarbageCollection::getDocumentsByAge( 1 );
$posts = GarbageCollection::get_documents_by_age( 1 );
if ( ! empty( $posts ) ) {
wp_schedule_single_event( time() + 1, 'wpgraphql_smart_cache_garbage_collect_deletes' );
}
Expand Down

0 comments on commit 037df6e

Please sign in to comment.