Skip to content

refactor: optimize polling and improve optimistic update stability#753

Open
SyedaAnshrahGillani wants to merge 1 commit intosupermemoryai:mainfrom
SyedaAnshrahGillani:fix/optimistic-update-and-polling-optimization
Open

refactor: optimize polling and improve optimistic update stability#753
SyedaAnshrahGillani wants to merge 1 commit intosupermemoryai:mainfrom
SyedaAnshrahGillani:fix/optimistic-update-and-polling-optimization

Conversation

@SyedaAnshrahGillani
Copy link

Summary of Changes

  1. Polling Optimization:

    • In packages/lib/queries.ts, I increased the refetchInterval for
      fetchSubscriptionStatus from 5 seconds to 60 seconds.
    • Impact: Subscription status is relatively static. Polling every 5
      seconds was unnecessarily aggressive, leading to excessive network
      traffic and load on the billing service (Autumn). Increasing this to 1
      minute significantly improves client performance and reduces server
      load without impacting user experience.
  2. Optimistic Update Stability:

    • In packages/lib/queries.ts, I refactored the onMutate logic in the
      useDeleteDocument mutation.
    • Impact: The previous implementation only handled the pages structure
      used by infinite queries. If the documents-with-memories query was used
      as a standard query elsewhere in the app, the optimistic update would
      have failed or caused runtime errors. The new implementation safely
      handles both standard query (flat documents array) and infinite query
      (paged documents) structures, ensuring UI consistency and robustness.
  3. Code Quality & Linting:

    • Refined the type narrowing in the setQueryData callback to satisfy
      Biome's linting rules, replacing any with safer unknown and
      Record<string, unknown> types.
    • Ensured the code follows the project's formatting standards by running
      biome check --write.

Verification

  • Ran bun install to ensure all dependencies and lockfiles are correctly
    synchronized.
  • Verified the changes with biome check to ensure no linting or formatting
    regressions.
  • Confirmed that the repository's build system (Turbo) and package manager
    (Bun) are correctly utilized.

- Increased subscription status refetch interval from 5s to 60s to reduce unnecessary network load.
- Improved 'useDeleteDocument' optimistic update to handle both standard and infinite query data structures, preventing potential runtime errors and ensuring UI consistency.
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.

2 participants