Skip to content

feat: caching#93

Open
ictbeheer wants to merge 7 commits into
mainfrom
feat/caching
Open

feat: caching#93
ictbeheer wants to merge 7 commits into
mainfrom
feat/caching

Conversation

@ictbeheer
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings June 2, 2026 06:29
@ictbeheer ictbeheer requested a review from a team as a code owner June 2, 2026 06:29
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Coverage report for commit: e546243
File: coverage.xml

Cover ┌─────────────────────────┐ Freq.
   0% │ ███████████████████████ │ 75.0%
  10% │ ██░░░░░░░░░░░░░░░░░░░░░ │  6.3%
  20% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  30% │ ██░░░░░░░░░░░░░░░░░░░░░ │  6.3%
  40% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  50% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  60% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  70% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  80% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  90% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
 100% │ ████░░░░░░░░░░░░░░░░░░░ │ 12.5%
      └─────────────────────────┘
 *Legend:* █ = Current Distribution 
Summary - Lines: 9.00% | Methods: 7.27%
FilesLinesMethodsBranches
src/Attributes
   Meta.php--100.00%
   MetaPrefix.php--100.00%
   TaxonomyPrefix.php--100.00%
   Terms.php--100.00%
src
   CommentData.php--100.00%
   ImageData.php--100.00%
   PostData.php8.27%7.41%100.00%
   TermData.php--100.00%
   UserData.php--100.00%
src/Contracts
   PostDataInterface.php100.00%100.00%100.00%
src/Enums
   PostStatus.php--100.00%
src/Mappers
   PostPrefixMapper.php--100.00%
   UserPrefixMapper.php--100.00%
src/Normalizers
   WPPostNormalizer.php--100.00%
src/Providers
   DataServiceProvider.php100.00%100.00%100.00%
src/Traits
   HasMeta.php25.00%-100.00%

🤖 comment via lucassabreu/comment-coverage-clover

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a wp_cache_get / wp_cache_set pair keyed by the entity ID under per-type cache groups (yard_user_data, yard_term_data, yard_post_data, yard_comment_data).
  • Uses instanceof static to 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.

Comment thread src/PostData.php Outdated
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');
Comment thread src/PostData.php Outdated
{
return new (self::dataClass($post->post_type))(
$cachedPostData = wp_cache_get($post->ID, 'yard_post_data', false, $found);
if ($found && $cachedPostData instanceof static) {
Comment thread src/PostData.php Outdated
{
return new (self::dataClass($post->post_type))(
$cachedPostData = wp_cache_get($post->ID, 'yard_post_data', false, $found);
if ($found && $cachedPostData instanceof static) {
Copy link
Copy Markdown
Member

@SimonvanWijhe SimonvanWijhe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏎️ 🏎️ 🏎️

Copy link
Copy Markdown

@mvdhoek1 mvdhoek1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goede toevoeging, heb je al een verschil kunnen merken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants