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

Feature: Issue-218: Cache Initial Post API Calls #219

Merged
merged 12 commits into from
Aug 21, 2024

Conversation

efuller
Copy link
Contributor

@efuller efuller commented Aug 16, 2024

Summary

This PR introduces SWR which will help to cache API responses that are identical calls. The useSWRImmutable hook is used so that automatic revalidation is not turned on.

Reviewer Notes

Will bump version after CR.

Description

When loading a page in the editor that is powered by the query block, there are several API calls to the API for gathering the posts needed. Many of these API calls are the same. Find a way to increase performance by minimizing the number of API calls upon load.

Testing

Before merging in, it would be great to get another set of 👀 on actual testing in the editor.

  1. Verify that query changes are reflected in real time in the editor
  2. Verify that deduplication is working
  3. Verify that pinned posts are working as they should

Ticket

Fixes #218

@efuller efuller marked this pull request as ready for review August 19, 2024 19:45
Copy link
Member

@kevinfodness kevinfodness left a comment

Choose a reason for hiding this comment

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

🍣

@@ -1,4 +1,5 @@
/* eslint-disable camelcase */
import useSWRImmutable from 'swr/immutable';
Copy link
Member

Choose a reason for hiding this comment

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

@efuller Does disabling automatic revalidation eliminate the need for workarounds like this one? https://l.alley.dev/ca8db44a8f

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dlh01 I think it could. useSWRImmutable will simply just cache an API call and unless that request changes in any way, it will continue to use the cache.

The use case I wanted to guard against was the revalidation after switching tabs. Here are some docs on revalidation and there are a ton of additional options as well.

I think it could be worth a try!

@efuller efuller merged commit cfc19e7 into develop Aug 21, 2024
5 checks passed
@efuller efuller deleted the feature/issue-218/cache-initial-query-api-calls branch August 21, 2024 16:17
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.

Cache Initial API Calls for Query Blocks
3 participants