Bug: [REFACTOR] Update Database Connection Functions for Read Operations



### 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:

- `crates/router/src/db/role.rs`
- `crates/router/src/db/user.rs`
- `crates/router/src/db/user_role.rs`
- `crates/router/src/db/dashboard_metadata.rs`


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?

- [X] I checked and didn't find a similar issue

### Submission Process:
- Ask the maintainers for assignment of the issue, you can request for assignment by commenting on the issue itself.
- Once assigned, submit a pull request (PR).
- Maintainers will review and provide feedback, if any. 
- Maintainers can unassign issues due to inactivity, [read more here](https://github.com/juspay/hyperswitch/wiki/Hacktoberfest-Contribution-Rules).

Refer [here](https://github.com/juspay/hyperswitch/blob/main/docs/TERMS_OF_CONTEST.md) for Terms and conditions for the contest.
diff --git a/crates/router/src/db/dashboard_metadata.rs b/crates/router/src/db/dashboard_metadata.rs
index f8aee34c49c..742c03dde4a 100644
--- a/crates/router/src/db/dashboard_metadata.rs
+++ b/crates/router/src/db/dashboard_metadata.rs
@@ -99,7 +99,7 @@ impl DashboardMetadataInterface for Store {
         org_id: &id_type::OrganizationId,
         data_keys: Vec<enums::DashboardMetadata>,
     ) -> CustomResult<Vec<storage::DashboardMetadata>, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::DashboardMetadata::find_user_scoped_dashboard_metadata(
             &conn,
             user_id.to_owned(),
@@ -118,7 +118,7 @@ impl DashboardMetadataInterface for Store {
         org_id: &id_type::OrganizationId,
         data_keys: Vec<enums::DashboardMetadata>,
     ) -> CustomResult<Vec<storage::DashboardMetadata>, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::DashboardMetadata::find_merchant_scoped_dashboard_metadata(
             &conn,
             merchant_id.to_owned(),
diff --git a/crates/router/src/db/role.rs b/crates/router/src/db/role.rs
index 20a4922d165..ce009d38a9e 100644
--- a/crates/router/src/db/role.rs
+++ b/crates/router/src/db/role.rs
@@ -80,7 +80,7 @@ impl RoleInterface for Store {
         &self,
         role_id: &str,
     ) -> CustomResult<storage::Role, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::Role::find_by_role_id(&conn, role_id)
             .await
             .map_err(|error| report!(errors::StorageError::from(error)))
@@ -93,7 +93,7 @@ impl RoleInterface for Store {
         merchant_id: &id_type::MerchantId,
         org_id: &id_type::OrganizationId,
     ) -> CustomResult<storage::Role, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::Role::find_by_role_id_in_merchant_scope(&conn, role_id, merchant_id, org_id)
             .await
             .map_err(|error| report!(errors::StorageError::from(error)))
@@ -105,7 +105,7 @@ impl RoleInterface for Store {
         role_id: &str,
         org_id: &id_type::OrganizationId,
     ) -> CustomResult<storage::Role, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::Role::find_by_role_id_in_org_scope(&conn, role_id, org_id)
             .await
             .map_err(|error| report!(errors::StorageError::from(error)))
@@ -140,7 +140,7 @@ impl RoleInterface for Store {
         merchant_id: &id_type::MerchantId,
         org_id: &id_type::OrganizationId,
     ) -> CustomResult<Vec<storage::Role>, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::Role::list_roles(&conn, merchant_id, org_id)
             .await
             .map_err(|error| report!(errors::StorageError::from(error)))
@@ -154,7 +154,7 @@ impl RoleInterface for Store {
         entity_type: Option<enums::EntityType>,
         limit: Option<u32>,
     ) -> CustomResult<Vec<storage::Role>, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::Role::generic_roles_list_for_org(
             &conn,
             org_id.to_owned(),
diff --git a/crates/router/src/db/user.rs b/crates/router/src/db/user.rs
index c9244eb12b4..3cf68551b52 100644
--- a/crates/router/src/db/user.rs
+++ b/crates/router/src/db/user.rs
@@ -71,7 +71,7 @@ impl UserInterface for Store {
         &self,
         user_email: &pii::Email,
     ) -> CustomResult<storage::User, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::User::find_by_user_email(&conn, user_email)
             .await
             .map_err(|error| report!(errors::StorageError::from(error)))
@@ -82,7 +82,7 @@ impl UserInterface for Store {
         &self,
         user_id: &str,
     ) -> CustomResult<storage::User, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::User::find_by_user_id(&conn, user_id)
             .await
             .map_err(|error| report!(errors::StorageError::from(error)))
@@ -127,7 +127,7 @@ impl UserInterface for Store {
         &self,
         user_ids: Vec<String>,
     ) -> CustomResult<Vec<storage::User>, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::User::find_users_by_user_ids(&conn, user_ids)
             .await
             .map_err(|error| report!(errors::StorageError::from(error)))
diff --git a/crates/router/src/db/user_role.rs b/crates/router/src/db/user_role.rs
index b589d375975..ceec7dd77d9 100644
--- a/crates/router/src/db/user_role.rs
+++ b/crates/router/src/db/user_role.rs
@@ -102,7 +102,7 @@ impl UserRoleInterface for Store {
         profile_id: Option<&id_type::ProfileId>,
         version: enums::UserRoleVersion,
     ) -> CustomResult<storage::UserRole, errors::StorageError> {
-        let conn = connection::pg_connection_write(self).await?;
+        let conn = connection::pg_connection_read(self).await?;
         storage::UserRole::find_by_user_id_org_id_merchant_id_profile_id(
             &conn,
             user_id.to_owned(),

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] 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
<!-- Put an `x` in the boxes that apply -->

- [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
