From a4913f10662a2ea238ab673e23f8f6b71def4c02 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: Fri, 1 Apr 2022 18:49:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=20[#103]feat:=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/.gitignore | 1 - ars/elk/logstash/logstash.conf | 25 ++++++++ ars/src/apis/art/art.resolver.ts | 61 +++++++++---------- .../apis/art/entities/artsSearch.entity.ts | 54 ++++++++++++++++ ars/src/common/graphql/schema.gql | 17 +++++- 5 files changed, 123 insertions(+), 35 deletions(-) create mode 100644 ars/elk/logstash/logstash.conf create mode 100644 ars/src/apis/art/entities/artsSearch.entity.ts diff --git a/ars/.gitignore b/ars/.gitignore index 87c6a9a..250e8fb 100644 --- a/ars/.gitignore +++ b/ars/.gitignore @@ -1,6 +1,5 @@ dev-antonym-341008-4b961b814f1a.json .env.dev -logstash.conf # compiled output /dist diff --git a/ars/elk/logstash/logstash.conf b/ars/elk/logstash/logstash.conf new file mode 100644 index 0000000..84e6a99 --- /dev/null +++ b/ars/elk/logstash/logstash.conf @@ -0,0 +1,25 @@ +input { + jdbc { + jdbc_driver_library => "/usr/share/logstash/mysql-connector-java-8.0.28.jar" + jdbc_driver_class => "com.mysql.cj.jdbc.Driver" + #jdbc_connection_string => "jdbc:mysql://10.90.0.4:3306/ars" + jdbc_connection_string => "jdbc:mysql://my_database:3306/ars" + jdbc_user => "root" + jdbc_password => "3160" + schedule => "* * * * *" + + use_column_value => true + tracking_column => "updatedat" + last_run_metadata_path => "./aaa.txt" + + tracking_column_type => "numeric" + statement => "select art.id, title, start_price, instant_bid, price, thumbnail, createdAt, deadline, tag1, tag2, tag3, tag4, updatedat, u.nickname, unix_timestamp(art.updatedat) as updatedat from art left join user as u ON art.userId = u.id where unix_timestamp(art.updatedat) > :sql_last_value order by updatedat asc" + } +} + +output { + elasticsearch { + hosts => "elasticsearch:9200" + index => "artipul00" + } +} \ No newline at end of file diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index 76ec03e..af90d55 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -14,6 +14,7 @@ import { CreateArtInput } from './dto/createArtInput'; import { Art } from './entities/art.entity'; import { Cache } from 'cache-manager'; import { CACHE_MANAGER, Inject } from '@nestjs/common'; +import { ArtsSearch } from './entities/artsSearch.entity'; @Resolver() export class ArtResolver { @@ -28,7 +29,7 @@ export class ArtResolver { private readonly paymentService: PaymentService, ) {} - @Query(() => [Art]) + @Query(() => [ArtsSearch]) async fetchArts( @Args('tag1') tag1: string, @Args('tag2', { nullable: true }) tag2: string, @@ -36,17 +37,17 @@ export class ArtResolver { @Args('tag4', { nullable: true }) tag4: string, ) { // redis에 캐시되어 있는지 확인하기 - const redisValue = await this.cacheManager.get( - `tag1: ${tag1}, tag2: ${tag2}, tag3: ${tag3}, tag4: ${tag4}`, - ); - if (redisValue) { - console.log(redisValue); - return redisValue; - } + // const redisValue = await this.cacheManager.get( + // `tag1: ${tag1}, tag2: ${tag2}, tag3: ${tag3}, tag4: ${tag4}`, + // ); + // if (redisValue) { + // console.log('💛', redisValue); + // return redisValue; + // } // 레디스에 캐시가 되어있지 않다면, 엘라스틱서치에서 조회하기(유저가 검색한 검색어로 조회하기) const result = await this.elasticsearchService.search({ - index: 'artipul01', + index: 'artipul00', query: { bool: { should: [ @@ -61,20 +62,24 @@ export class ArtResolver { if (!result.hits.hits.length) return null; - const artTags = result.hits.hits.map((el: any) => ({ - id: el._source.id, - title: el._source.title, - start_price: el._source.start_price, - instant_bid: el._source.instant_bid, - price: el._source.price, - deadline: el._source.deadline, - thumbnail: el._source.thumbnail, - tag1: el._source.tag1, - tag2: el._source.tag2, - tag3: el._source.tag3, - tag4: el._source.tag4, - nickname: el._source.nickname, - })); + const artTags = result.hits.hits.map((el: any) => { + return { + id: el._source.id, + title: el._source.title, + start_price: el._source.start_price, + instant_bid: el._source.instant_bid, + price: el._source.price, + deadline: el._source.deadline, + thumbnail: el._source.thumbnail, + tag1: el._source.tag1, + tag2: el._source.tag2, + tag3: el._source.tag3, + tag4: el._source.tag4, + nickname: el._source.nickname, + }; + }); + + console.log(artTags); // 엘라스틱서치에서 조회 결과가 있다면, 레디스에 검색결과 캐싱해놓기 await this.cacheManager.set( @@ -179,16 +184,6 @@ export class ArtResolver { @Args('createArtInput') createArtInput: CreateArtInput, // @CurrentUser() currentUser: ICurrentUser, ) { - //엘라스틱서치에서 등록할때 한번 사용 후 주석 - // await this.elasticsearchService.create({ - // id: 'artipulid01', - // index: 'artipul01', - // document: { - // ...createArtInput, - // currentUser, - // }, - // }); - return this.artService.create({ ...createArtInput }, currentUser); } diff --git a/ars/src/apis/art/entities/artsSearch.entity.ts b/ars/src/apis/art/entities/artsSearch.entity.ts new file mode 100644 index 0000000..bff902b --- /dev/null +++ b/ars/src/apis/art/entities/artsSearch.entity.ts @@ -0,0 +1,54 @@ +import { Field, Int, ObjectType } from '@nestjs/graphql'; +import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; + +@Entity() +@ObjectType() +export class ArtsSearch { + @PrimaryGeneratedColumn('uuid') + @Field(() => String) + id: string; + + @Column() + @Field(() => String) + title: string; + + @Column() + @Field(() => Int) + start_price: number; + + @Column() + @Field(() => Int) + instant_bid: number; + + @Column({ default: null }) + @Field(() => Int) + price: number; + + @Column() + @Field(() => String) + thumbnail: string; + + @Column() + @Field(() => Date) + deadline: Date; + + @Column() + @Field(() => String) + tag1: string; + + @Column({ nullable: true, default: null }) + @Field(() => String, { nullable: true }) + tag2?: string; + + @Column({ nullable: true, default: null }) + @Field(() => String, { nullable: true }) + tag3?: string; + + @Column({ nullable: true, default: null }) + @Field(() => String, { nullable: true }) + tag4?: string; + + @Column() + @Field(() => String) + nickname: string; +} diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index 28ef128..f553e6e 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -96,6 +96,21 @@ type History { payment: Payment } +type ArtsSearch { + id: String! + title: String! + start_price: Int! + instant_bid: Int! + price: Int! + thumbnail: String! + deadline: DateTime! + tag1: String! + tag2: String + tag3: String + tag4: String + nickname: String! +} + type Board { id: String! title: String! @@ -120,7 +135,7 @@ type Comment { } type Query { - fetchArts(tag1: String!, tag2: String, tag3: String, tag4: String): [Art!]! + fetchArts(tag1: String!, tag2: String, tag3: String, tag4: String): [ArtsSearch!]! fetchArt(artId: String!): Art! fetchArtImages(artId: String!): [ArtImage!]! fetchEngageCount: Float! From 58d4b01d58b9e7cdc29e271b892d15bc35bdbcd5 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: Fri, 1 Apr 2022 18:51:32 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[#108]feat:=20=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=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/art/art.resolver.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index af90d55..24ec8f6 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -36,14 +36,13 @@ export class ArtResolver { @Args('tag3', { nullable: true }) tag3: string, @Args('tag4', { nullable: true }) tag4: string, ) { - // redis에 캐시되어 있는지 확인하기 - // const redisValue = await this.cacheManager.get( - // `tag1: ${tag1}, tag2: ${tag2}, tag3: ${tag3}, tag4: ${tag4}`, - // ); - // if (redisValue) { - // console.log('💛', redisValue); - // return redisValue; - // } + //redis에 캐시되어 있는지 확인하기 + const redisValue = await this.cacheManager.get( + `tag1: ${tag1}, tag2: ${tag2}, tag3: ${tag3}, tag4: ${tag4}`, + ); + if (redisValue) { + return redisValue; + } // 레디스에 캐시가 되어있지 않다면, 엘라스틱서치에서 조회하기(유저가 검색한 검색어로 조회하기) const result = await this.elasticsearchService.search({ @@ -79,8 +78,6 @@ export class ArtResolver { }; }); - console.log(artTags); - // 엘라스틱서치에서 조회 결과가 있다면, 레디스에 검색결과 캐싱해놓기 await this.cacheManager.set( `tag1: ${tag1}, tag2: ${tag2}, tag3: ${tag3}, tag4: ${tag4}`,