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

feat: fetch only latest open PR from DB #769

Merged
merged 6 commits into from
May 24, 2023

Conversation

harishv7
Copy link
Contributor

@harishv7 harishv7 commented May 18, 2023

Problem

Currently we are fetching all the PRs (Open + Closed) from our DB. Then we do a for-loop over every PR to get its meta, number of comments etc. from Github API.

This causes unnecessary calls to Github. In line with our effort to reduce Github API calls, and with the fact that there could be at most 1 open PR for a repo (so far), we can further streamline this.

Closes IS-171

Solution

We only retrieve the latest (newest by createdAt timestamp) PR that is in "OPEN" or "APPROVED" state.

Since we may have more than 1 Open PR in future, the changes allow for us to revert back to using findAll in a relatively simple way.

Breaking Changes

  • Yes - this PR contains breaking changes
    • Details ...
  • No - this PR is backwards compatible

Test Cases

Site dashboard

  • should show only 1 open or approved review request

Workspace

  • should show the review request alert when there's a review request open

site edit header (this is used widely)

  • should disable the review request button when there's an open review request
    approved review redirect (used widely)

  • should redirect when there's an approved review request
    more broadly, we want to test for this property (can't think of good test cases off the top of my head):

essentially, if there's an open/approved RR, we can't raise any more RR
verified by @kishore03109

@harishv7 harishv7 requested review from seaerchin, kishore03109 and alexanderleegs and removed request for seaerchin May 18, 2023 02:24
kishore03109
kishore03109 previously approved these changes May 18, 2023
Copy link
Contributor

@kishore03109 kishore03109 left a comment

Choose a reason for hiding this comment

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

[Nit] I would rather have this function to only resolve one promise with no comments rather than a map over the array + add a todo saying we can change this to findAll when we allow multiple PRs in the future since we are not certain about the future and this comment might end up being obsolete/redundant down the line if we never intend to do so.

[Tests] Tests are failing :( I am approving this on the assumption that making the tests pass does not require a change in the ReviewRequestService.ts. Please dismiss this review if that is not true.

@harishv7
Copy link
Contributor Author

[Nit] I would rather have this function to only resolve one promise with no comments rather than a map over the array + add a todo saying we can change this to findAll when we allow multiple PRs in the future since we are not certain about the future and this comment might end up being obsolete/redundant down the line if we never intend to do so.

[Tests] Tests are failing :( I am approving this on the assumption that making the tests pass does not require a change in the ReviewRequestService.ts. Please dismiss this review if that is not true.

@kishore03109 Hmm, this PR is based on the assumption that we are tackling multiple open PRs in the near term roadmap. That's the reason the implementation was done as a "short-term" fix

But if you were to change it to a single promise, then the return type of the function will become Promise which is different. As such the changes will cascade to the caller's return type and the logic as well and cascade on the tests we have.

The reason behind the changes are that we want the simplest path to unroll back into using findAll to return multiple results.

@harishv7 harishv7 requested a review from kishore03109 May 19, 2023 02:42
@harishv7 harishv7 force-pushed the IS-171-retrieve-open-p-rs-from-db-call branch from fe480e1 to c3bb67a Compare May 19, 2023 09:50
where: {
siteId: site.id,
reviewStatus: ReviewRequestStatus.Open,
Copy link
Contributor

Choose a reason for hiding this comment

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

Sanity check here: do we only want open reviews? Dont we also need Approved and/or closedones because they are open but have not been merged in yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kishore03109 During discussion we agreed to fetch the latest open PR, which I felt referred to the PRs in "open" status.

@seaerchin Do we need to displays Approved/Closed PRs which are not yet merged?

Copy link
Contributor

Choose a reason for hiding this comment

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

good catch @kishore03109! i searched the FE for this - we'd need to give both APPROVED | OPEN states. could i also trouble you (@harishv7) to rename this + the route to listValidReviewRequests for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done with renaming and fetching for both approved + open states. As discussed,

There can only exist 1 active PR which is in either Open or Approved state. The new logic will fetch the most recently created PR DB entry which is in Open/Approved state

Copy link
Contributor

Choose a reason for hiding this comment

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

wait sanity check, the code here still filters by reviewStatus: ReviewRequestStatus.Open, and not by approved + open state, is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kishore03109 Looking at https://github.com/isomerpages/isomercms-backend/pull/769/files#diff-ec790b65dee9ec111ee3c30c98efd651b561a57b31c998d06b200db95e68255f, code is updated to

const request = await this.repository.findOne({
      where: {
        siteId: site.id,
        [Op.or]: [
          {
            reviewStatus: ReviewRequestStatus.Open,
          },
          { reviewStatus: ReviewRequestStatus.Approved },
        ],
      },

seaerchin
seaerchin previously approved these changes May 19, 2023
src/services/review/ReviewRequestService.ts Show resolved Hide resolved
@seaerchin seaerchin dismissed stale reviews from kishore03109 and themself May 19, 2023 10:14

missing condition

@seaerchin
Copy link
Contributor

Hey, just searched the FE for this endpoint and added test cases below! feel free to copy as-is to the PR description and/or add on!

Site dashboard

  • should show only 1 open or approved review request

workspace

  • should show the review request alert when there's a review request open

site edit header (this is used widely)

  • should disable the review request button when there's an open review request

approved review redirect (used widely)

  • should redirect when there's an approved review request

more broadly, we want to test for this property (can't think of good test cases off the top of my head):

  1. if there's an open/approved RR, we can't raise any more RR

this might be out of scope at present, but we might wanna check if creation of RR is blocked on BE also

@harishv7 harishv7 merged commit f3bf0aa into develop May 24, 2023
@harishv7 harishv7 deleted the IS-171-retrieve-open-p-rs-from-db-call branch May 24, 2023 07:19
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.

3 participants