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/GitHub duplication #1818

Merged
merged 22 commits into from
Jan 18, 2024
Merged

Feat/GitHub duplication #1818

merged 22 commits into from
Jan 18, 2024

Conversation

joyguptaa
Copy link
Contributor

@joyguptaa joyguptaa commented Dec 28, 2023

Date: 28 Dec 2023

Developer Name: Joy Gupta


Issue Ticket Number:-

Reference PR:-

Description:

  1. Created a script to add github_user_id into user schema to avoid user duplication
  2. Also saving github_user_id upon logging if it does not exists

Is Under the Feature Flag

  • Yes
  • No

Database changes

  • Yes
  • No

Breaking changes (If your feature is breaking/missing something please mention pending tickets)

  • Yes
  • No

Is Development Tested?

  • Yes
  • No

Tested in staging?

  • Yes
  • No

Test Cases

Screenshot 2024-01-16 at 9 00 21 PM

Test Stats

Screenshot 2024-01-16 at 9 01 20 PM

Add relevant Screenshot below

1. Github user id should be added upon logging in

Screen.Recording.2023-12-28.at.9.59.42.AM.1.mov

2. Should add github_user_id after executing the script

Before

Screen.Recording.2023-12-28.at.10.21.26.AM.mov

Execution log

Screenshot 2023-12-28 at 10 21 52 AM

Updated Users

Screen.Recording.2023-12-28.at.10.21.59.AM.mov

routes/users.js Fixed Show fixed Hide fixed
Copy link
Contributor

@Ajeyakrishna-k Ajeyakrishna-k left a comment

Choose a reason for hiding this comment

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

Please add the following:

  • Test coverage screenshots
  • Integration tests

const userId = userDoc.id;
batchWrite.update(userDoc.ref, { github_user_id: null });

const promise = fetch(`https://api.github.com/users/${githubUsername}`, requestOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we considered GitHub's rate limits?

Copy link
Contributor Author

@joyguptaa joyguptaa Jan 2, 2024

Choose a reason for hiding this comment

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

The doc says that it is 5000 requests per hour for authenticated users. And I do not think that this will cause any issue as we anyway have less than 1k users.

Copy link
Contributor

Choose a reason for hiding this comment

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

It also says we cannot make more than 900 calls per minute on a single route. I think we have around 3000 users docs in our prod db.
https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-secondary-rate-limits
Screenshot 2024-01-07 at 10 05 44 PM
Screenshot 2024-01-07 at 10 07 39 PM

controllers/users.js Outdated Show resolved Hide resolved
controllers/users.js Outdated Show resolved Hide resolved
models/users.js Show resolved Hide resolved
routes/users.js Outdated Show resolved Hide resolved
routes/users.js Fixed Show fixed Hide fixed
@joyguptaa
Copy link
Contributor Author

Please add the following:

  • Test coverage screenshots
  • Integration tests

Done

models/users.js Outdated Show resolved Hide resolved
const userId = userDoc.id;
batchWrite.update(userDoc.ref, { github_user_id: null });

const promise = fetch(`https://api.github.com/users/${githubUsername}`, requestOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

It also says we cannot make more than 900 calls per minute on a single route. I think we have around 3000 users docs in our prod db.
https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-secondary-rate-limits
Screenshot 2024-01-07 at 10 05 44 PM
Screenshot 2024-01-07 at 10 07 39 PM

controllers/users.js Outdated Show resolved Hide resolved
models/users.js Outdated Show resolved Hide resolved
// WARNING!! - One time Script/Route to do migration
router.post(
"/migrations",
authenticate,

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
test/unit/models/users.test.js Show resolved Hide resolved
middlewares/validators/user.js Show resolved Hide resolved
Copy link
Contributor

@Ajeyakrishna-k Ajeyakrishna-k left a comment

Choose a reason for hiding this comment

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

  • Unit tests should have been written for models and middleware instead of only having integration tests.
    Please also get approvals from @prakashchoudhary07 / @iamitprakash.

Copy link
Member

@iamitprakash iamitprakash left a comment

Choose a reason for hiding this comment

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

can you test case stats

@iamitprakash iamitprakash merged commit 535545c into develop Jan 18, 2024
2 of 3 checks passed
@iamitprakash iamitprakash deleted the feat/github-duplication branch January 18, 2024 15:52
@joyguptaa joyguptaa mentioned this pull request Jan 19, 2024
10 tasks
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.

None yet

3 participants