diff --git a/dictation_server/db/migrations/055-add_users_index.sql b/dictation_server/db/migrations/055-add_users_index.sql new file mode 100644 index 0000000..ea50c9d --- /dev/null +++ b/dictation_server/db/migrations/055-add_users_index.sql @@ -0,0 +1,5 @@ +-- +migrate Up +ALTER TABLE `users` ADD INDEX `idx_role` (role); + +-- +migrate Down +ALTER TABLE `users` DROP INDEX `idx_role`; \ No newline at end of file diff --git a/dictation_server/src/repositories/user_groups/user_groups.repository.service.ts b/dictation_server/src/repositories/user_groups/user_groups.repository.service.ts index e7db5cf..050d3e1 100644 --- a/dictation_server/src/repositories/user_groups/user_groups.repository.service.ts +++ b/dictation_server/src/repositories/user_groups/user_groups.repository.service.ts @@ -122,8 +122,8 @@ export class UserGroupsRepositoryService { role: USER_ROLES.TYPIST, email_verified: true, }, - comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, lock: { mode: 'pessimistic_write' }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (userRecords.length !== typistIds.length) { throw new TypistIdInvalidError( @@ -189,8 +189,8 @@ export class UserGroupsRepositoryService { role: USER_ROLES.TYPIST, email_verified: true, }, - comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, lock: { mode: 'pessimistic_write' }, + comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (userRecords.length !== typistIds.length) { throw new TypistIdInvalidError( @@ -206,6 +206,7 @@ export class UserGroupsRepositoryService { id: typistGroupId, account_id: accountId, }, + lock: { mode: 'pessimistic_write' }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, }); if (!typistGroup) { diff --git a/dictation_server/src/repositories/workflows/workflows.repository.service.ts b/dictation_server/src/repositories/workflows/workflows.repository.service.ts index de5e38e..2ccaf5e 100644 --- a/dictation_server/src/repositories/workflows/workflows.repository.service.ts +++ b/dictation_server/src/repositories/workflows/workflows.repository.service.ts @@ -101,6 +101,7 @@ export class WorkflowsRepositoryService { const worktypes = await worktypeRepo.find({ where: { account_id: accountId, id: worktypeId }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + lock: { mode: 'pessimistic_write' }, }); if (worktypes.length === 0) { throw new WorktypeIdNotFoundError( @@ -115,6 +116,7 @@ export class WorkflowsRepositoryService { const template = await templateRepo.findOne({ where: { account_id: accountId, id: templateId }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + lock: { mode: 'pessimistic_write' }, }); if (!template) { throw new TemplateFileNotExistError('template not found.'); @@ -132,6 +134,7 @@ export class WorkflowsRepositoryService { email_verified: true, }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + lock: { mode: 'pessimistic_write' }, }); if (typistUsers.length !== typistIds.length) { throw new UserNotFoundError( @@ -147,6 +150,7 @@ export class WorkflowsRepositoryService { const typistGroups = await userGroupRepo.find({ where: { account_id: accountId, id: In(groupIds) }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + lock: { mode: 'pessimistic_write' }, }); if (typistGroups.length !== groupIds.length) { throw new TypistGroupNotExistError( @@ -164,6 +168,7 @@ export class WorkflowsRepositoryService { worktype_id: worktypeId !== undefined ? worktypeId : IsNull(), }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + lock: { mode: 'pessimistic_write' }, }); if (workflow.length !== 0) { throw new AuthorIdAndWorktypeIdPairAlreadyExistsError( @@ -264,6 +269,7 @@ export class WorkflowsRepositoryService { const targetWorkflow = await workflowRepo.findOne({ where: { account_id: accountId, id: workflowId }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + lock: { mode: 'pessimistic_write' }, }); if (!targetWorkflow) { throw new WorkflowNotFoundError( @@ -277,6 +283,7 @@ export class WorkflowsRepositoryService { const worktypes = await worktypeRepo.find({ where: { account_id: accountId, id: worktypeId }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + lock: { mode: 'pessimistic_write' }, }); if (worktypes.length === 0) { throw new WorktypeIdNotFoundError( @@ -291,6 +298,7 @@ export class WorkflowsRepositoryService { const template = await templateRepo.findOne({ where: { account_id: accountId, id: templateId }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + lock: { mode: 'pessimistic_write' }, }); if (!template) { throw new TemplateFileNotExistError( @@ -402,6 +410,7 @@ export class WorkflowsRepositoryService { const workflow = await workflowRepo.findOne({ where: { account_id: accountId, id: workflowId }, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, + lock: { mode: 'pessimistic_write' }, }); if (!workflow) { throw new WorkflowNotFoundError(