hyperswitch icon indicating copy to clipboard operation
hyperswitch copied to clipboard

refactor(users): Update Database connection for Read only functions

Open zeel991 opened this issue 1 year ago • 7 comments

Type of Change

  • [ ] Bugfix
  • [ ] New feature
  • [ ] Enhancement
  • [x] Refactoring
  • [ ] Dependency updates
  • [ ] Documentation
  • [ ] CI/CD

Description

This PR refactors the database connection logic by changing the function from pg_connection_write() to pg_connection_read() for functions that only perform read operations from the database. This is an internal change aimed at optimizing resource usage. All user-facing APIs should continue to function as expected without any disruptions.

Additional Changes

  • [ ] This PR modifies the API contract
  • [ ] This PR modifies the database schema
  • [ ] This PR modifies application configuration/environment variables

Motivation and Context

This change is required to improve efficiency by ensuring that we use the appropriate connection type for read operations. It resolves the inefficiency of using write connections for read-only database queries.

  • Fixes https://github.com/juspay/hyperswitch/issues/5965

How did you test it?

  • Verified that all user-related APIs are working without any issues.
  • All existing test cases for database read and write operations passed successfully.
  • Confirmed that this internal change does not affect the functionality of user-facing APIs.

Checklist

  • [x] I formatted the code cargo +nightly fmt --all
  • [ ] I addressed lints thrown by cargo clippy
  • [x] I reviewed the submitted code
  • [x] I added unit tests for my changes where possible

zeel991 avatar Sep 30 '24 19:09 zeel991

Review changes with SemanticDiff.

Analyzed 4 of 4 files.

Filename Status
:heavy_check_mark: crates/router/src/db/dashboard_metadata.rs Analyzed
:heavy_check_mark: crates/router/src/db/role.rs Analyzed
:heavy_check_mark: crates/router/src/db/user.rs Analyzed
:heavy_check_mark: crates/router/src/db/user_role.rs Analyzed

semanticdiff-com[bot] avatar Sep 30 '24 19:09 semanticdiff-com[bot]

Please add something in description saying that this is a internal change and all the user related APIs should work without any issues in the testcases section.

ThisIsMani avatar Oct 01 '24 11:10 ThisIsMani

Please add something in description saying that this is a internal change and all the user related APIs should work without any issues in the testcases section.

Done @ThisIsMani , I apologize for any beginner mistakes I made while raising this PR. Thank you for your patience and support

zeel991 avatar Oct 01 '24 11:10 zeel991

Hey @zeel991, can you check the original template and change you PR description into that template.

ThisIsMani avatar Oct 01 '24 11:10 ThisIsMani

Hey @zeel991, can you check the original template and change you PR description into that template.

Are these changes appropriate ?

zeel991 avatar Oct 01 '24 12:10 zeel991

Yeah, looks fine.

ThisIsMani avatar Oct 01 '24 12:10 ThisIsMani

Hello @ThisIsMani ,would you please consider adding the hactoberfest tag to the PR

zeel991 avatar Oct 01 '24 14:10 zeel991

Hey @ThisIsMani , since this PR is approved, when can it be merged ?

zeel991 avatar Oct 03 '24 03:10 zeel991

@zeel991, will get this merged by Monday.

ThisIsMani avatar Oct 04 '24 04:10 ThisIsMani

Hey @zeel991, can you resolve the conflicts.

ThisIsMani avatar Oct 04 '24 11:10 ThisIsMani

Hey @zeel991, can you resolve the conflicts.

Done ! 👍🏻

zeel991 avatar Oct 04 '24 14:10 zeel991

Hello @ThisIsMani , I am Zeel Darji , C4GT community Lead and Open source Lead of Development Wing of IIITN . I am organizing an open source event in my college's techfest which higlights the importance of DPGs and DPIs .

I wanted to ask you if participants could contribute to the repos of Juspay for our Event ?

zeel991 avatar Oct 04 '24 19:10 zeel991

Hey @zeel991, Happy to help with the event. Pinged you in community workspace, we can continue the discussion there.

gorakhnathy7 avatar Oct 05 '24 03:10 gorakhnathy7

Hey @zeel991, Happy to help with the event. Pinged you in community workspace, we can continue the discussion there.

Can you please send the link , I couldn't find it

zeel991 avatar Oct 05 '24 06:10 zeel991

Hey @zeel991, Happy to help with the event. Pinged you in community workspace, we can continue the discussion there.

Can you please send the link , I couldn't find it

Please check Hyperswitch Slack workspace

gorakhnathy7 avatar Oct 06 '24 04:10 gorakhnathy7

@ThisIsMani Should I update the branch ?

zeel991 avatar Oct 07 '24 11:10 zeel991

@ThisIsMani Should I update the branch ?

Not needed.

ThisIsMani avatar Oct 07 '24 12:10 ThisIsMani

But seems like formatting check if failing in the PR, can you format the code using just fmt and push the changes.

ThisIsMani avatar Oct 07 '24 12:10 ThisIsMani

But seems like formatting check if failing in the PR, can you format the code using just fmt and push the changes.

I have removed the merge conflict and formatted the PR

zeel991 avatar Oct 08 '24 13:10 zeel991

Hey @ThisIsMani If my contribution is as required , can you please merge my PR , as I have been getting conflicts

zeel991 avatar Oct 09 '24 13:10 zeel991

@ThisIsMani All the tests have passed

zeel991 avatar Oct 09 '24 15:10 zeel991

Hey @zeel991, your PR has been approved, It will take some time for it to be merged, Kindly check in after 15th October

ThisIsMani avatar Oct 09 '24 16:10 ThisIsMani