From c904877ff0d262063125533db4858eb9d92eff12 Mon Sep 17 00:00:00 2001 From: tnpfldyd Date: Fri, 8 Dec 2023 16:15:43 +0900 Subject: [PATCH 1/7] =?UTF-8?q?fix(#212):=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=20=EC=8B=9C=20=EC=83=9D=EA=B8=B0=EB=8A=94=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nestjs-BE/server/src/profile-space/profile-space.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nestjs-BE/server/src/profile-space/profile-space.service.ts b/nestjs-BE/server/src/profile-space/profile-space.service.ts index 1adbdea2..be51e63a 100644 --- a/nestjs-BE/server/src/profile-space/profile-space.service.ts +++ b/nestjs-BE/server/src/profile-space/profile-space.service.ts @@ -107,7 +107,7 @@ export class ProfileSpaceService extends BaseService { }, }); const storeUserSpaces = - profileResponse.spaces.map((profileSpace) => profileSpace.space) || []; + profileResponse?.spaces.map((profileSpace) => profileSpace.space) || []; return storeUserSpaces; } From def67e37d6a1fd29b33d0179567ae551b3e536b6 Mon Sep 17 00:00:00 2001 From: tnpfldyd Date: Fri, 8 Dec 2023 17:05:54 +0900 Subject: [PATCH 2/7] =?UTF-8?q?fix(#212):=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EB=B6=88=EB=9F=AC=EC=98=A4=EB=8A=94=20=EB=B0=A9=EC=8B=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nestjs-BE/server/src/profile-space/profile-space.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nestjs-BE/server/src/profile-space/profile-space.service.ts b/nestjs-BE/server/src/profile-space/profile-space.service.ts index be51e63a..93534f68 100644 --- a/nestjs-BE/server/src/profile-space/profile-space.service.ts +++ b/nestjs-BE/server/src/profile-space/profile-space.service.ts @@ -147,7 +147,7 @@ export class ProfileSpaceService extends BaseService { const users = await this.getSpaceUsers(spaceUuid); const usersData = await Promise.all( users.map(async (user) => { - return await this.profilesService.getDataFromCacheOrDB(user.user_id); + return await this.profilesService.findOne(user.user_id); }), ); this.spaceCache.put(spaceUuid, usersData); From e7b8736a0b89bd3f7556ee778c2e83d88ea70c60 Mon Sep 17 00:00:00 2001 From: tnpfldyd Date: Mon, 11 Dec 2023 11:01:03 +0900 Subject: [PATCH 3/7] =?UTF-8?q?fix(#212):=20=EC=9E=84=EC=8B=9C=20db=20?= =?UTF-8?q?=EB=B6=88=ED=95=84=EC=9A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temporary-database.service.ts | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/nestjs-BE/server/src/temporary-database/temporary-database.service.ts b/nestjs-BE/server/src/temporary-database/temporary-database.service.ts index 6e9ec3b8..07fa0cf8 100644 --- a/nestjs-BE/server/src/temporary-database/temporary-database.service.ts +++ b/nestjs-BE/server/src/temporary-database/temporary-database.service.ts @@ -17,7 +17,6 @@ interface OperationData { @Injectable() export class TemporaryDatabaseService { private database: Map>> = new Map(); - private entriesMap: Map = new Map(); private readonly FOLDER_NAME = 'operations'; constructor( @@ -112,7 +111,7 @@ export class TemporaryDatabaseService { }); } - @Cron('* * * * * *') + @Cron('0 */10 * * * *') async executeBulkOperations() { for (const service of this.database.keys()) { const serviceMap = this.database.get(service); @@ -130,7 +129,6 @@ export class TemporaryDatabaseService { prisma: PrismaServiceMongoDB | PrismaServiceMySQL, ) { const data = this.prepareData(service, 'insert', dataMap); - this.entriesMap.clear(); if (!data.length) return; if (prisma instanceof PrismaServiceMySQL) { await prisma[service].createMany({ @@ -200,23 +198,4 @@ export class TemporaryDatabaseService { private clearFile(filename: string) { fs.writeFile(join(this.FOLDER_NAME, filename), '', 'utf8'); } - - getEntries(key: string): string[] { - return this.entriesMap.get(key) || []; - } - - addEntry(key: string, value: string): void { - const entries = this.getEntries(key); - entries.push(value); - this.entriesMap.set(key, entries); - } - - removeEntry(key: string, value: string): void { - const entries = this.getEntries(key); - const index = entries.indexOf(value); - if (index > -1) { - entries.splice(index, 1); - this.entriesMap.set(key, entries); - } - } } From 3538c47b18508f06371977840fa357f239d42870 Mon Sep 17 00:00:00 2001 From: tnpfldyd Date: Mon, 11 Dec 2023 11:03:38 +0900 Subject: [PATCH 4/7] =?UTF-8?q?fix(#212):=20=EC=8A=A4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20=EA=B8=B0=EB=B3=B8?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20url=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/BE-deploy.yml | 2 ++ nestjs-BE/server/src/spaces/spaces.controller.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/BE-deploy.yml b/.github/workflows/BE-deploy.yml index 8cdca3cf..b4321865 100644 --- a/.github/workflows/BE-deploy.yml +++ b/.github/workflows/BE-deploy.yml @@ -28,6 +28,7 @@ jobs: echo "STORAGE_URL=$STORAGE_URL" >> ./nestjs-BE/server/.env echo "BASE_IMAGE_URL=$BASE_IMAGE_URL" >> ./nestjs-BE/server/.env echo "BUCKET_NAME=$BUCKET_NAME" >> ./nestjs-BE/server/.env + echo "APP_ICON_URL=$APP_ICON_URL" >> ./nestjs-BE/server/.env docker build -t ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync ./nestjs-BE/server docker push ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync:latest env: @@ -44,6 +45,7 @@ jobs: STORAGE_URL: ${{ secrets.STORAGE_URL }} BASE_IMAGE_URL: ${{ secrets.BASE_IMAGE_URL }} BUCKET_NAME: ${{ secrets.BUCKET_NAME }} + APP_ICON_URL: ${{ secrets.APP_ICON_URL }} deploy: needs: build diff --git a/nestjs-BE/server/src/spaces/spaces.controller.ts b/nestjs-BE/server/src/spaces/spaces.controller.ts index 565a155d..39c025fd 100644 --- a/nestjs-BE/server/src/spaces/spaces.controller.ts +++ b/nestjs-BE/server/src/spaces/spaces.controller.ts @@ -18,7 +18,7 @@ import { UploadService } from 'src/upload/upload.service'; import { ProfileSpaceService } from 'src/profile-space/profile-space.service'; import { RequestWithUser } from 'src/utils/interface'; import customEnv from 'src/config/env'; -const { BASE_IMAGE_URL } = customEnv; +const { APP_ICON_URL } = customEnv; @Controller('spaces') @ApiTags('spaces') @@ -43,7 +43,7 @@ export class SpacesController { ) { const iconUrl = icon ? await this.uploadService.uploadFile(icon) - : BASE_IMAGE_URL; + : APP_ICON_URL; createSpaceDto.icon = iconUrl; const response = await this.spacesService.create(createSpaceDto); const { uuid: spaceUuid } = response.data; From 972de9c5878d79c3418b97061e3faa24bf0c2810 Mon Sep 17 00:00:00 2001 From: tnpfldyd Date: Mon, 11 Dec 2023 11:46:41 +0900 Subject: [PATCH 5/7] =?UTF-8?q?fix(#212):=20=EC=9D=BC=EB=B6=80=20any=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temporary-database.service.ts | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/nestjs-BE/server/src/temporary-database/temporary-database.service.ts b/nestjs-BE/server/src/temporary-database/temporary-database.service.ts index 07fa0cf8..96463bc1 100644 --- a/nestjs-BE/server/src/temporary-database/temporary-database.service.ts +++ b/nestjs-BE/server/src/temporary-database/temporary-database.service.ts @@ -6,17 +6,42 @@ import { import { Cron } from '@nestjs/schedule'; import { promises as fs } from 'fs'; import { join } from 'path'; +import { TokenData } from 'src/auth/auth.service'; +import { InviteCodeData } from 'src/invite-codes/invite-codes.service'; +import { CreateProfileSpaceDto } from 'src/profile-space/dto/create-profile-space.dto'; +import { UpdateProfileDto } from 'src/profiles/dto/update-profile.dto'; +import { UpdateSpaceDto } from 'src/spaces/dto/update-space.dto'; +import { UpdateUserDto } from 'src/users/dto/update-user.dto'; + +type DeleteDataType = { + field: string; + value: string; +}; + +type InsertDataType = + | TokenData + | InviteCodeData + | CreateProfileSpaceDto + | UpdateProfileDto + | UpdateSpaceDto + | UpdateUserDto; + +type UpdateDataType = { + field: string; + value: InsertDataType; +}; +type DataType = InsertDataType | UpdateDataType | DeleteDataType; interface OperationData { service: string; uniqueKey: string; command: string; - data: any; + data: DataType; } @Injectable() export class TemporaryDatabaseService { - private database: Map>> = new Map(); + private database: Map>> = new Map(); private readonly FOLDER_NAME = 'operations'; constructor( @@ -78,15 +103,15 @@ export class TemporaryDatabaseService { return this.database.get(service).get(command).get(uniqueKey); } - create(service: string, uniqueKey: string, data: any) { + create(service: string, uniqueKey: string, data: InsertDataType) { this.operation({ service, uniqueKey, command: 'insert', data }); } - update(service: string, uniqueKey: string, data: any) { + update(service: string, uniqueKey: string, data: UpdateDataType) { this.operation({ service, uniqueKey, command: 'update', data }); } - remove(service: string, uniqueKey: string, data: any) { + remove(service: string, uniqueKey: string, data: DeleteDataType) { this.operation({ service, uniqueKey, command: 'delete', data }); } @@ -125,7 +150,7 @@ export class TemporaryDatabaseService { private async performInsert( service: string, - dataMap: Map, + dataMap: Map, prisma: PrismaServiceMongoDB | PrismaServiceMySQL, ) { const data = this.prepareData(service, 'insert', dataMap); @@ -144,7 +169,7 @@ export class TemporaryDatabaseService { private async performUpdate( service: string, - dataMap: Map, + dataMap: Map, prisma: PrismaServiceMongoDB | PrismaServiceMySQL, ) { const data = this.prepareData(service, 'update', dataMap); @@ -166,7 +191,7 @@ export class TemporaryDatabaseService { private async performDelete( service: string, - dataMap: Map, + dataMap: Map, prisma: PrismaServiceMongoDB | PrismaServiceMySQL, ) { const data = this.prepareData(service, 'delete', dataMap); From 366fd6c1719462986f4df98c42713fd8cbda05ee Mon Sep 17 00:00:00 2001 From: tnpfldyd Date: Mon, 11 Dec 2023 15:28:12 +0900 Subject: [PATCH 6/7] =?UTF-8?q?fix(#212):=20csv=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=9D=84=20=EC=99=B8=EB=B6=80=EC=97=90=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=20=EB=B3=BC=EB=A5=A8=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/BE-deploy.yml | 8 +++++++- nestjs-BE/server/Dockerfile | 2 -- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/BE-deploy.yml b/.github/workflows/BE-deploy.yml index b4321865..0ae4aeef 100644 --- a/.github/workflows/BE-deploy.yml +++ b/.github/workflows/BE-deploy.yml @@ -29,6 +29,7 @@ jobs: echo "BASE_IMAGE_URL=$BASE_IMAGE_URL" >> ./nestjs-BE/server/.env echo "BUCKET_NAME=$BUCKET_NAME" >> ./nestjs-BE/server/.env echo "APP_ICON_URL=$APP_ICON_URL" >> ./nestjs-BE/server/.env + echo "CSV_FOLDER=$CSV_FOLDER" >> ./nestjs-BE/server/.env docker build -t ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync ./nestjs-BE/server docker push ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync:latest env: @@ -46,6 +47,7 @@ jobs: BASE_IMAGE_URL: ${{ secrets.BASE_IMAGE_URL }} BUCKET_NAME: ${{ secrets.BUCKET_NAME }} APP_ICON_URL: ${{ secrets.APP_ICON_URL }} + CSV_FOLDER: ${{ secrets.CSV_FOLDER }} deploy: needs: build @@ -63,4 +65,8 @@ jobs: docker pull ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync docker stop mindsync_server || true docker rm mindsync_server || true - docker run -d --name mindsync_server -p ${{ secrets.SERVER_PORT }}:${{ secrets.CONTAINER_PORT }} ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync + docker run -d \ + --name mindsync_server \ + -p ${{ secrets.SERVER_PORT }}:${{ secrets.CONTAINER_PORT }} \ + -v temporary-volume:${{ secrets.CSV_FOLDER }} \ + ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync diff --git a/nestjs-BE/server/Dockerfile b/nestjs-BE/server/Dockerfile index 9eb851c7..26d49afc 100644 --- a/nestjs-BE/server/Dockerfile +++ b/nestjs-BE/server/Dockerfile @@ -12,8 +12,6 @@ RUN npx prisma generate --schema=./prisma/mysql.schema.prisma RUN npx prisma generate --schema=./prisma/mongodb.schema.prisma -RUN mkdir operations - EXPOSE 3000 CMD ["npm", "start"] From 2cece3c36259e664c2ffed1fa28ce7d56ea5c432 Mon Sep 17 00:00:00 2001 From: tnpfldyd Date: Mon, 11 Dec 2023 15:28:33 +0900 Subject: [PATCH 7/7] =?UTF-8?q?fix(#212):=20=ED=8C=8C=EC=9D=BC=20=EC=9D=BD?= =?UTF-8?q?=EA=B3=A0=20=EC=93=B0=EB=8A=94=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temporary-database.service.ts | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/nestjs-BE/server/src/temporary-database/temporary-database.service.ts b/nestjs-BE/server/src/temporary-database/temporary-database.service.ts index 96463bc1..de993400 100644 --- a/nestjs-BE/server/src/temporary-database/temporary-database.service.ts +++ b/nestjs-BE/server/src/temporary-database/temporary-database.service.ts @@ -12,6 +12,8 @@ import { CreateProfileSpaceDto } from 'src/profile-space/dto/create-profile-spac import { UpdateProfileDto } from 'src/profiles/dto/update-profile.dto'; import { UpdateSpaceDto } from 'src/spaces/dto/update-space.dto'; import { UpdateUserDto } from 'src/users/dto/update-user.dto'; +import costomEnv from 'src/config/env'; +const { CSV_FOLDER } = costomEnv; type DeleteDataType = { field: string; @@ -42,15 +44,19 @@ interface OperationData { @Injectable() export class TemporaryDatabaseService { private database: Map>> = new Map(); - private readonly FOLDER_NAME = 'operations'; + private readonly FOLDER_NAME = CSV_FOLDER; constructor( private readonly prismaMysql: PrismaServiceMySQL, private readonly prismaMongoDB: PrismaServiceMongoDB, ) { + this.init(); + } + + async init() { this.initializeDatabase(); - this.readDataFromFiles(); - this.executeBulkOperations(); + await this.readDataFromFiles(); + await this.executeBulkOperations(); } private initializeDatabase() { @@ -76,11 +82,11 @@ export class TemporaryDatabaseService { private async readDataFromFiles() { const files = await fs.readdir(this.FOLDER_NAME); - files.forEach((file) => { - if (file.endsWith('.csv')) { - this.readDataFromFile(file); - } - }); + return Promise.all( + files + .filter((file) => file.endsWith('.csv')) + .map((file) => this.readDataFromFile(file)), + ); } private async readDataFromFile(file: string) { @@ -129,11 +135,7 @@ export class TemporaryDatabaseService { operation({ service, uniqueKey, command, data }: OperationData) { const filePath = join(this.FOLDER_NAME, `${service}-${command}.csv`); - fs.readFile(filePath, 'utf8').then((fileData) => { - fileData += `${uniqueKey},${JSON.stringify(data)}\n`; - fs.writeFile(filePath, fileData); - this.database.get(service).get(command).set(uniqueKey, data); - }); + fs.appendFile(filePath, `${uniqueKey},${JSON.stringify(data)}\n`, 'utf8'); } @Cron('0 */10 * * * *')