Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

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

Zeel Darjifba4a027dfe1
diff --git a/crates/router/src/db/dashboard_metadata.rs b/crates/router/src/db/dashboard_metadata.rs
index f8aee34c49..742c03dde4 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 20a4922d16..ce009d38a9 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 c9244eb12b..3cf68551b5 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 1fa70afa73..d32c6b254e 100644
--- a/crates/router/src/db/user_role.rs
+++ b/crates/router/src/db/user_role.rs
@@ -103,7 +103,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(),