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

fix: update document flow fetch logic #1039

Merged
merged 6 commits into from
Mar 26, 2024
Merged

Conversation

dguyen
Copy link
Collaborator

@dguyen dguyen commented Mar 20, 2024

Description

Fixes issues with mismatching state between document steps.

For example, editing a recipient and proceeding to the next step may not display the updated recipient. And going back will display the old recipient instead of the updated values.

This PR also improves mutation and query speeds by adding logic to bypass query invalidation.

export const trpc = createTRPCReact<AppRouter>({
  unstable_overrides: {
    useMutation: {
      async onSuccess(opts) {
        await opts.originalFn();

        // This forces mutations to wait for all the queries on the page to reload, and in
        // this case one of the queries is `searchDocument` for the command overlay, which
        // on average takes ~500ms. This means that every single mutation must wait for this.
        await opts.queryClient.invalidateQueries(); 
      },
    },
  },
});

I've added workarounds to allow us to bypass things such as batching and invalidating queries. But I think we should instead remove this and update all the mutations where a query is required for a more optimised system.

Example benchmarks

Using stg-app vs this preview there's an average 50% speed increase across mutations.

Set signer step:
Average old speed: ~1100ms
Average new speed: ~550ms

Set recipient step:
Average old speed: ~1200ms
Average new speed: ~600ms

Set fields step:
Average old speed: ~1200ms
Average new speed: ~600ms

Related Issue

This will resolve #470

Changes Made

  • Added ability to skip batch queries
  • Added a state to store the required document data.
  • Refetch the data between steps if/when required
  • Optimise mutations and queries

Checklist

  • I have tested these changes locally and they work as expected.
  • I have followed the project's coding style guidelines.

Copy link
Contributor

coderabbitai bot commented Mar 20, 2024

Important

Auto Review Skipped

Auto reviews are limited to the following labels: coderabbit. Please add one of these labels to enable auto reviews.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

vercel bot commented Mar 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stg-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2024 3:39am
stg-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2024 3:39am
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
prd-app ⬜️ Ignored (Inspect) Mar 25, 2024 3:39am
prd-marketing ⬜️ Ignored (Inspect) Mar 25, 2024 3:39am

@Mythie
Copy link
Collaborator

Mythie commented Mar 20, 2024

Dumb question and I get why you've done it, but instead of maintaining the useStates you could instead just change up the queryClient cache to update the getWithDetails query.

This would yield the same kind of result but without us managing it as directly.

Edit: I realise above isn't really a question

@dguyen
Copy link
Collaborator Author

dguyen commented Mar 20, 2024

It's done this way so we can use the results from the TPRC mutations to update the relevant data, which reduces loading times

Unless I'm misunderstanding what you're suggesting

The query is just to ensure we refresh every now and then.

Copy link
Collaborator

Mythie commented Mar 21, 2024

Apologies, I seem to have a hard time expressing myself this week.

My point is rather than doing this state locally you can use utils.setData to update the queryClient's data for the getDocumentWithDetails query.

This would avoid the busy work of maintaining state ourself while also keeping everything updated without refetching.

@dguyen
Copy link
Collaborator Author

dguyen commented Mar 21, 2024

Ah I see I'll have a look.

Pretty annoying it seems like we have to leave router refresh in since we need to clear the router cache for documents page 😩

Tempted to use trpc to render the documents page for client side at a later time

@dguyen
Copy link
Collaborator Author

dguyen commented Mar 22, 2024

Applied the changes and the PR is now ready for review

@Mythie
Copy link
Collaborator

Mythie commented Mar 25, 2024

I assume we will need to do the same for templates as well 😬

@dguyen
Copy link
Collaborator Author

dguyen commented Mar 25, 2024

I retested your changes and they work, anything else to do for this?

@Mythie
Copy link
Collaborator

Mythie commented Mar 26, 2024

I retested your changes and they work, anything else to do for this?

Lets do templates in a separate PR

@dguyen dguyen merged commit 006b732 into main Mar 26, 2024
13 checks passed
@dguyen dguyen deleted the fix/edit-document-data-refresh branch March 26, 2024 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apps: web Issues related to the webapp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG Signer fields cannot be edited/removed after modifying the signer.
2 participants