From 4548b5e5107bd941db0f177f2d5f636abd949b49 Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Fri, 2 Feb 2024 02:37:39 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20715:=20=E8=A1=8C=E3=83=AD?= =?UTF-8?q?=E3=83=83=E3=82=AF=E6=A8=AA=E5=B1=95=E9=96=8B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3472: 行ロック横展開4](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3472) - 対象メソッド - user_groups - createTypistGroup - グループに含めるユーザー情報取得箇所でロック追加 - ユーザー削除と被ると、削除済みユーザーをユーザーグループに含めてしまう - updateTypistGroup - グループに含めるユーザー情報取得箇所でロック追加 - ユーザー削除と被ると、削除済みユーザーをユーザーグループに含めてしまう - グループの存在確認を行う箇所 - グループ削除と被ると、削除済みのグループにメンバーを割り当ててしまう - workflows - createtWorkflows - updatetWorkflow - インデックス追加 - user - role ## レビューポイント - インデックスの貼り忘れはないか - ロックの追加忘れはないか ## 共有資料 - https://ndstokyo.sharepoint.com/:f:/r/sites/Piranha/Shared%20Documents/General/OMDS/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88/Task3472?csf=1&web=1&e=jjb0QV ## 動作確認状況 - ローカルでロックされている箇所で待ちが発生していることを確認 ## 補足 - 相談、参考資料などがあれば --- dictation_server/db/migrations/055-add_users_index.sql | 5 +++++ .../user_groups/user_groups.repository.service.ts | 5 +++-- .../workflows/workflows.repository.service.ts | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 dictation_server/db/migrations/055-add_users_index.sql 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(