feat: caching#93
Conversation
|
Coverage report for commit: e546243 Summary - Lines: 9.00% | Methods: 7.27%
🤖 comment via lucassabreu/comment-coverage-clover |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
Adds a simple read-through caching layer to the four data factories (UserData::fromUser, TermData::fromTerm, PostData::fromPost / fromCorcel, CommentData::fromComment) using WordPress's object cache API to avoid repeatedly rebuilding the same data objects within (and, with a persistent cache backend, across) requests.
Changes:
- Wraps each
from*factory with awp_cache_get/wp_cache_setpair keyed by the entity ID under per-type cache groups (yard_user_data,yard_term_data,yard_post_data,yard_comment_data). - Uses
instanceof staticto validate cached values before returning them. - No corresponding cache invalidation logic is introduced.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/UserData.php | Caches UserData instances by user ID under yard_user_data. |
| src/TermData.php | Caches TermData instances by term ID under yard_term_data. |
| src/PostData.php | Caches PostData instances built from both WP_Post and Corcel Post by post ID under yard_post_data. |
| src/CommentData.php | Caches CommentData instances by comment ID under yard_comment_data. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| thumbnail: get_post_thumbnail_id($post->ID) ? new ImageData(get_post_thumbnail_id($post->ID)) : null, | ||
| commentCount: post_type_supports($post->post_type, 'comments') ? (int) $post->comment_count : null, | ||
| ); | ||
| wp_cache_set($post->ID, $postData, 'yard_post_data'); |
| { | ||
| return new (self::dataClass($post->post_type))( | ||
| $cachedPostData = wp_cache_get($post->ID, 'yard_post_data', false, $found); | ||
| if ($found && $cachedPostData instanceof static) { |
| { | ||
| return new (self::dataClass($post->post_type))( | ||
| $cachedPostData = wp_cache_get($post->ID, 'yard_post_data', false, $found); | ||
| if ($found && $cachedPostData instanceof static) { |
mvdhoek1
left a comment
There was a problem hiding this comment.
Goede toevoeging, heb je al een verschil kunnen merken?
2290e5e
Het wordt merkbaar bij grote aantallen posts bijv. uit wp-events, met ca. 400 posts gaat de event pagina van 1,00 naar 0,7 seconden. |
No description provided.