fix: Eliminate N+1 API calls for interactive templates in flow editor - #4002
Open
sentry[bot] wants to merge 1 commit into
Open
fix: Eliminate N+1 API calls for interactive templates in flow editor#4002sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
|
🚀 Deployed on https://deploy-preview-4002--glific-frontend.netlify.app |
Glific
|
||||||||||||||||||||||||||||
| Project |
Glific
|
| Branch Review |
seer/fix/n-plus-1-interactive-templates
|
| Run status |
|
| Run duration | 06m 45s |
| Commit |
|
| Committer | sentry[bot] |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
32
|
| View all changes introduced in this branch ↗︎ | |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR addresses the N+1 API call issue observed on
/flow/configure/*pages, specifically for interactive templates.Problem:
When loading a flow in the editor, the underlying
@nyaruka/temba-componentslibrary makes individual HTTP GET requests to/flow-editor/interactive-templates/{id}for each interactive template referenced in the flow. This results in a significant number of redundant network calls, impacting performance.Solution:
Introduces a
setupInteractiveTemplateCachefunction inFlowEditor.helper.tsxthat patcheswindow.fetch. This interceptor works as follows:interactive-templates/{id}is made, it triggers a single network call to the list endpoint (/flow-editor/interactive-templates) to fetch all available templates.interactive-templates/{id}are served directly from this cache, eliminating further network calls.This approach significantly reduces network overhead and improves the loading performance of the flow editor when dealing with multiple interactive templates. The
window.fetchpatch is properly cleaned up when the component unmounts, following the pattern established bysetAuthHeaders.Test Plan
/flow/configure/some-flow-id) that contains multiple interactive templates./flow-editor/interactive-templates(the list endpoint).GET /flow-editor/interactive-templates/{id}requests are made over the network for each template, as they should be served from the cache.Fixes GLIFIC-FRONTEND-13G