Skip to content

Commit

Permalink
Merge pull request #109 from Daseul1/feat/#108
Browse files Browse the repository at this point in the history
Feat/#108
  • Loading branch information
Daseul1 committed Apr 1, 2022
2 parents e4f4a71 + f5073ea commit 6eae714
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 31 deletions.
1 change: 0 additions & 1 deletion ars/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dev-antonym-341008-4b961b814f1a.json
.env.dev
logstash.conf

# compiled output
/dist
Expand Down
25 changes: 25 additions & 0 deletions ars/elk/logstash/logstash.conf
Original file line number Diff line number Diff line change
@@ -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"
}
}
49 changes: 20 additions & 29 deletions ars/src/apis/art/art.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,24 +29,23 @@ export class ArtResolver {
private readonly paymentService: PaymentService,
) {}

@Query(() => [Art])
@Query(() => [ArtsSearch])
async fetchArts(
@Args('tag1') tag1: string,
@Args('tag2', { nullable: true }) tag2: string,
@Args('tag3', { nullable: true }) tag3: string,
@Args('tag4', { nullable: true }) tag4: string,
) {
// redis에 캐시되어 있는지 확인하기
//redis에 캐시되어 있는지 확인하기
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: [
Expand All @@ -60,20 +60,22 @@ 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,
};
});

// 엘라스틱서치에서 조회 결과가 있다면, 레디스에 검색결과 캐싱해놓기
await this.cacheManager.set(
Expand Down Expand Up @@ -180,17 +182,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);
}

Expand Down
54 changes: 54 additions & 0 deletions ars/src/apis/art/entities/artsSearch.entity.ts
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 16 additions & 1 deletion ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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!
Expand Down

0 comments on commit 6eae714

Please sign in to comment.