-
Notifications
You must be signed in to change notification settings - Fork 16
feat: Add garbage collection cleanup admin and cron job #227
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
Merged
markkelnar
merged 30 commits into
wp-graphql:main
from
markkelnar:feature/garbage-collect-aged-queries
Aug 9, 2023
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c4d2efa
Add garbage collection cleanup admin and cron job
markkelnar ebe21a2
Delete in smaller batch events instead of all posts
markkelnar dc3db02
bump some version numbers
markkelnar 63d3716
Add tests for admin settings garbage collection options
markkelnar 81b4885
Add garbage collection unit tests
markkelnar e9166b8
Merge remote-tracking branch 'origin/main' into feature/garbage-colle…
markkelnar 456d979
Get age from settings value in utils class
markkelnar 9ff1e21
Add admin editor ability to skip garbage collection per query
markkelnar 378ebed
Add tax_query to gargage collection to ignore where docs opt out
markkelnar 1334dfc
Rename garbage collection class
markkelnar 025b7c7
Add groups collection for documents. Refactor garbage collection to i…
markkelnar f8e6a7a
fix code sniff white space
markkelnar 72dd923
Update gc text in graphql settings to talk about groups
markkelnar 0f7baaa
Add the word "delete" to text
markkelnar c99ab11
Merge remote-tracking branch 'origin/main' into feature/garbage-colle…
markkelnar 614a874
Use garbage_collect instead of gc
markkelnar a55d6e9
text description change.
markkelnar 037df6e
snake case function name
markkelnar 5af7178
Merge remote-tracking branch 'me/feature/garbage-collect-aged-queries…
markkelnar 55fc784
fix for consistent names
markkelnar 514894a
enable admin quick-edit for document groups
markkelnar b65efd9
Merge remote-tracking branch 'origin/main' into feature/garbage-colle…
markkelnar 22cf8f5
Merge commit '9a023bfd9243b02f80861c56fab9c20d04c4a79a' into feature/…
jasonbahl 35168d9
re-add allow-plugin for codesniffer-installer
markkelnar 294bbee
Merge remote-tracking branch 'me/feature/garbage-collect-aged-queries…
markkelnar 19923e0
add filter for garbage collect recurrence
markkelnar 2495e72
merge fixes
markkelnar 3a7f141
composer update
markkelnar 92dbc42
Merge branch 'main' into feature/garbage-collect-aged-queries
jasonbahl 7923d53
fix phpstan suggestions
markkelnar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <?php | ||
| /** | ||
| * Content | ||
| * | ||
| * @package Wp_Graphql_Smart_Cache | ||
| */ | ||
|
|
||
| namespace WPGraphQL\SmartCache\Document; | ||
|
|
||
| use WPGraphQL\SmartCache\Admin\Settings; | ||
| use WPGraphQL\SmartCache\Document; | ||
| use WPGraphQL\SmartCache\Document\Group; | ||
| use GraphQL\Server\RequestError; | ||
|
|
||
| class GarbageCollection { | ||
|
|
||
| /** | ||
| * @param integer $number_of_posts Number of post ids matching criteria. | ||
| * | ||
| * @return int[] Array of post ids | ||
| */ | ||
| 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_garbage_collect_age', null, 'graphql_persisted_queries_section' ); | ||
| if ( 1 > $days_ago || ! is_numeric( $days_ago ) ) { | ||
| return []; | ||
| } | ||
|
|
||
| // Query for saved query documents that are older than age and not skipping garbage collection. | ||
| // Get documents where no group taxonmy term is set. | ||
| $wp_query = new \WP_Query( | ||
| [ | ||
| 'post_type' => Document::TYPE_NAME, | ||
| 'post_status' => 'publish', | ||
jasonbahl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 'posts_per_page' => $number_of_posts, | ||
| 'fields' => 'ids', | ||
| 'date_query' => [ | ||
| [ | ||
| 'column' => 'post_modified_gmt', | ||
| 'before' => $days_ago . ' days ago', | ||
| ], | ||
| ], | ||
| // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query | ||
| 'tax_query' => [ | ||
| [ | ||
| 'taxonomy' => Group::TAXONOMY_NAME, | ||
markkelnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 'field' => 'name', | ||
| 'operator' => 'NOT EXISTS', | ||
| ], | ||
| ], | ||
| ] | ||
| ); | ||
|
|
||
| /** | ||
| * Because 'fields' returns 'ids', this returns array of post ints. Satisfy phpstan. | ||
| * | ||
| * @var int[] | ||
| */ | ||
| return $wp_query->get_posts(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php | ||
| /** | ||
| * Content | ||
| * | ||
| * @package Wp_Graphql_Smart_Cache | ||
| */ | ||
|
|
||
| namespace WPGraphQL\SmartCache\Document; | ||
|
|
||
| use WPGraphQL\SmartCache\Admin\Settings; | ||
| use WPGraphQL\SmartCache\Document; | ||
|
|
||
| class Group { | ||
|
|
||
| const TAXONOMY_NAME = 'graphql_document_group'; | ||
|
|
||
| /** | ||
| * @return void | ||
| */ | ||
| public function init() { | ||
| register_taxonomy( | ||
| self::TAXONOMY_NAME, | ||
| Document::TYPE_NAME, | ||
| [ | ||
| 'description' => __( 'Tag the saved query document with other queries as a "group".', 'wp-graphql-smart-cache' ), | ||
| 'labels' => [ | ||
| 'name' => __( 'Groups', 'wp-graphql-smart-cache' ), | ||
| 'singular_name' => __( 'Group', 'wp-graphql-smart-cache' ), | ||
| ], | ||
| 'hierarchical' => false, | ||
| 'public' => false, | ||
| 'publicly_queryable' => false, | ||
| 'show_admin_column' => true, | ||
| 'show_in_menu' => Settings::show_in_admin(), | ||
| 'show_ui' => Settings::show_in_admin(), | ||
| 'show_in_quick_edit' => true, | ||
| 'show_in_graphql' => true, | ||
| 'graphql_single_name' => 'graphqlDocumentGroup', | ||
| 'graphql_plural_name' => 'graphqlDocumentGroups', | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Look up the first group for a post | ||
| * | ||
| * @param int $post_id The post id | ||
| * @return string | ||
| */ | ||
| public static function get( $post_id ) { | ||
| $item = get_the_terms( $post_id, self::TAXONOMY_NAME ); | ||
| return ! is_wp_error( $item ) && isset( $item[0] ) && property_exists( $item[0], 'name' ) ? $item[0]->name : ''; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.