From f2c4822fe8e9657a6106bfab25a5f6606a20aa2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=8B=A4=EC=8A=AC?= <95472052+Daseul1@users.noreply.github.com> Date: Sun, 3 Apr 2022 15:13:47 +0900 Subject: [PATCH] =?UTF-8?q?[#122]feat:=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/likeBoard/likeBoard.service.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ars/src/apis/likeBoard/likeBoard.service.ts b/ars/src/apis/likeBoard/likeBoard.service.ts index d56c72f..88fb281 100644 --- a/ars/src/apis/likeBoard/likeBoard.service.ts +++ b/ars/src/apis/likeBoard/likeBoard.service.ts @@ -1,9 +1,7 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Connection, getRepository, Repository } from 'typeorm'; -import { Board } from '../board/entities/board.entity'; import { LikeBoard } from '../board/entities/likeBoard.entity'; -import { User } from '../user/entities/user.entity'; @Injectable() export class LikeBoardService { @@ -17,12 +15,14 @@ export class LikeBoardService { async find(userId) { const queryRunner = this.connection.createQueryRunner(); await queryRunner.connect(); - await queryRunner.startTransaction(); + await queryRunner.startTransaction('SERIALIZABLE'); try { const boards = await queryRunner.manager.find(LikeBoard, { where: { userId }, relations: ['board'], + lock: { mode: 'pessimistic_write' }, }); + await queryRunner.commitTransaction(); return boards.map((ele) => ele.board); } catch (error) { await queryRunner.rollbackTransaction(); @@ -35,9 +35,8 @@ export class LikeBoardService { async like(boardId, userId) { const queryRunner = this.connection.createQueryRunner(); await queryRunner.connect(); - await queryRunner.startTransaction(); + await queryRunner.startTransaction('SERIALIZABLE'); try { - const board = await queryRunner.manager.findOne(Board, { id: boardId }); const prevLike = await queryRunner.manager.findOne(LikeBoard, { where: { userId: userId, @@ -47,7 +46,7 @@ export class LikeBoardService { if (!prevLike) { await queryRunner.manager.save(LikeBoard, { userId: userId, - board: board, + board: boardId, }); await queryRunner.commitTransaction(); return true;