mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 15:40:47 +00:00
feat: switched read db operations to replica nodes
This commit is contained in:
@@ -22,7 +22,8 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
// -------------------------
|
||||
const findUserEncKeyByUsername = async ({ username }: { username: string }) => {
|
||||
try {
|
||||
return await db(TableName.Users)
|
||||
return await db
|
||||
.replicaNode()(TableName.Users)
|
||||
.where({
|
||||
username,
|
||||
isGhost: false
|
||||
@@ -36,7 +37,7 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findUserEncKeyByUserIdsBatch = async ({ userIds }: { userIds: string[] }, tx?: Knex) => {
|
||||
try {
|
||||
return await (tx || db)(TableName.Users)
|
||||
return await (tx || db.replicaNode())(TableName.Users)
|
||||
.where({
|
||||
isGhost: false
|
||||
})
|
||||
@@ -49,7 +50,8 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findUserEncKeyByUserId = async (userId: string) => {
|
||||
try {
|
||||
const user = await db(TableName.Users)
|
||||
const user = await db
|
||||
.replicaNode()(TableName.Users)
|
||||
.where(`${TableName.Users}.id`, userId)
|
||||
.join(TableName.UserEncryptionKey, `${TableName.Users}.id`, `${TableName.UserEncryptionKey}.userId`)
|
||||
.first();
|
||||
@@ -65,7 +67,8 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findUserByProjectMembershipId = async (projectMembershipId: string) => {
|
||||
try {
|
||||
return await db(TableName.ProjectMembership)
|
||||
return await db
|
||||
.replicaNode()(TableName.ProjectMembership)
|
||||
.where({ [`${TableName.ProjectMembership}.id` as "id"]: projectMembershipId })
|
||||
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
||||
.first();
|
||||
@@ -76,7 +79,8 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findUsersByProjectMembershipIds = async (projectMembershipIds: string[]) => {
|
||||
try {
|
||||
return await db(TableName.ProjectMembership)
|
||||
return await db
|
||||
.replicaNode()(TableName.ProjectMembership)
|
||||
.whereIn(`${TableName.ProjectMembership}.id`, projectMembershipIds)
|
||||
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
||||
.select("*");
|
||||
@@ -128,7 +132,7 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
// ---------------------
|
||||
const findOneUserAction = (filter: TUserActionsUpdate, tx?: Knex) => {
|
||||
try {
|
||||
return (tx || db)(TableName.UserAction).where(filter).first("*");
|
||||
return (tx || db.replicaNode())(TableName.UserAction).where(filter).first("*");
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Find one user action" });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user