juspay / hyperswitch

An open source payments switch written in Rust to make payments fast, reliable and affordable
https://hyperswitch.io/
Apache License 2.0
11.68k stars 1.23k forks source link

[REFACTOR] Update Database Connection Functions for Read Operations #5965

Open ThisIsMani opened 4 days ago

ThisIsMani commented 4 days ago

Feature Description

Currently, in our codebase, we are using pg_connection_write for database operations even when performing read operations, which is inefficient. The pg_connection_write function should only be used when we need to perform write operations. For read operations, we should use pg_connection_read to optimize resource usage.

Possible Implementation

Find occurrences of the usage of pg_connection_write for read operations and replace them with pg_connection_read in the following files:

  1. Open each of the specified files and search for functions that are performing read operations (for e.g., find_by_*, get_*) but are using pg_connection_write.
  2. Replace the usage of pg_connection_write with pg_connection_read in these functions.
  3. Ensure that the database calls still behave correctly and no write operations are mistakenly changed.

Have you spent some time checking if this feature request has been raised before?

Have you read the Contributing Guidelines?

Are you willing to submit a PR?

No, but I'm happy to collaborate on a PR with someone else

zeel991 commented 14 hours ago

Hey @ThisIsMani according to the description , the files , namely dashboard_metadata.rs , user_role.rs , user.rs and role.rs , have methods which either read from the database or write or maybe update the database using pg_connection_write() , so to solve this problem , we need to identify where the database is used to read , like in functions like find_by_user_email() and change the pg_connection_write() to pg_connection_read() , If I am correct, I would like to go ahead and work on this issue