Skip to content

[Due for payment 2025-05-22] [$250] Remove unnecessary Read api call s on the workspace features pages #61061

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

Open
mountiny opened this issue Apr 29, 2025 · 11 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@mountiny
Copy link
Contributor

mountiny commented Apr 29, 2025

Coming from here

On some of the workspace feature pages, we call the OpenPolicyFeatureX API command additionally when the RHP modal is closed.

For example:

  1. Go to Members page
  2. Open the workspace member detail page in RHP
  3. Close the RHP
  4. Notice in the Networks tab that the OpenPolicyFeatureX command was called again

Similar thing is happening on the report fields page too and possibly on some other pages too. It does not happen on all the pages so potentially the solution is quick

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021917178062594162758
  • Upwork Job ID: 1917178062594162758
  • Last Price Increase: 2025-04-29
Issue OwnerCurrent Issue Owner: @RachCHopkins
Issue OwnerCurrent Issue Owner: @martasudol
@mountiny mountiny added AutoAssignerNewDotQuality Used to assign quality issues to engineers Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor labels Apr 29, 2025
Copy link

melvin-bot bot commented Apr 29, 2025

Job added to Upwork: https://www.upwork.com/jobs/~021917178062594162758

@melvin-bot melvin-bot bot changed the title Remove unnecessary Read api call s on the workspace features pages [$250] Remove unnecessary Read api call s on the workspace features pages Apr 29, 2025
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 29, 2025
Copy link

melvin-bot bot commented Apr 29, 2025

Triggered auto assignment to Contributor-plus team member for initial proposal review - @s77rt (External)

Copy link

melvin-bot bot commented Apr 29, 2025

Current assignee @mountiny is eligible for the AutoAssignerNewDotQuality assigner, not assigning anyone new.

Copy link

melvin-bot bot commented Apr 29, 2025

Triggered auto assignment to @RachCHopkins (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@ishakakkad
Copy link
Contributor

ishakakkad commented Apr 29, 2025

Proposal

Please re-state the problem that we are trying to solve in this issue.

Remove unnecessary Read api call s on the workspace features pages

What is the root cause of that problem?

For some of the pages we use useFocusEffect for ex, here and some of the pages we used isFocused state inside the useEffect for ex, here . So whenever page is focused we call the API to get the data.

What changes do you think we should make in order to solve the problem?

To fix this issue we need to replace to useFocusEffect with useEffect. And whenever we use isFocused we should remove that and load the data only when page first time loads or whenever needed (can be checked during implementation)

  1. replace useFocusEffect with useEffect

useFocusEffect(
useCallback(() => {
fetchPolicyData();
}, [fetchPolicyData]),
);

  1. following code should not be execute when isFocused changed.

getWorkspaceMembers();

Make same kind of changes in other pages whenever needed.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

NA UI issue

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@nabi-ebrahimi
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

On some workspace feature pages (e.g., Members and Report Fields), the OpenPolicyFeatureX API command is unnecessarily triggered when the Right-Hand Panel (RHP) is closed. This results in redundant API calls that waste bandwidth and can impact performance.

What is the root cause of that problem?

A useEffect hook that listens to the isFocused state is calling getWorkspaceMembers() whenever the focus changes. Since closing the RHP updates the focus, this effect is incorrectly triggered even when no meaningful data update is required, leading to the repeated API call.

What changes do you think we should make in order to solve the problem?

We should update the following useEffect block: here

Original:

useEffect(() => {
    if (!isFocused) {
        setSelectedEmployees([]);
        return;
    }
    getWorkspaceMembers();
}, [isFocused]);

Updated:

useEffect(() => {
    if (!isFocused) {
        setSelectedEmployees([]);
        return;
    }

    // Avoid unnecessary API call if employee list already exists
    if (isEmptyObject(policy?.employeeList)) {
        getWorkspaceMembers();
    }
}, [isFocused, policy?.employeeList]);

This ensures getWorkspaceMembers() is only called when the page gains focus and the employee list is empty—avoiding the redundant API call on RHP close.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

N/A

What alternative solutions did you explore? (Optional)

@mountiny mountiny removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 29, 2025
@mountiny
Copy link
Contributor Author

This is handled by callstack as the initial assignment suggests.

We need to make sure this is called when the page is opened/ navigated from deelinks and in narrow view too

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Apr 30, 2025
@mallenexpensify mallenexpensify removed the AutoAssignerNewDotQuality Used to assign quality issues to engineers label May 13, 2025
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels May 15, 2025
@melvin-bot melvin-bot bot changed the title [$250] Remove unnecessary Read api call s on the workspace features pages [Due for payment 2025-05-22] [$250] Remove unnecessary Read api call s on the workspace features pages May 15, 2025
Copy link

melvin-bot bot commented May 15, 2025

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label May 15, 2025
Copy link

melvin-bot bot commented May 15, 2025

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.45-21 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2025-05-22. 🎊

For reference, here are some details about the assignees on this issue:

  • @s77rt requires payment through NewDot Manual Requests
  • @martasudol does not require payment (Contractor)

Copy link

melvin-bot bot commented May 15, 2025

@s77rt @RachCHopkins @s77rt The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

@s77rt
Copy link
Contributor

s77rt commented May 19, 2025

BugZero Checklist:

  • [Contributor] Classify the bug:
Bug classification

Source of bug:

  • 1a. Result of the original design (eg. a case wasn't considered)
  • 1b. Mistake during implementation
  • 1c. Backend bug
  • 1z. Other:

Where bug was reported:

  • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
  • 2b. Reported on staging (eg. found during regression or PR testing)
  • 2d. Reported on a PR
  • 2z. Other: Slack thread while working on fixing another similar bug

Who reported the bug:

  • 3a. Expensify user
  • 3b. Expensify employee
  • 3c. Contributor
  • 3d. QA
  • 3z. Other:
  • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

    Link to comment: Fix: Read API is not triggered consistently when switching between features of a Collect workspace #38613 (comment)

  • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

    Link to discussion: n/a

  • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Bug requires regression test: No. I don't think this qualifies for a test

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Weekly KSv2 labels May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
Status: LOW
Development

No branches or pull requests

7 participants