Posts ๐Ÿฅ ์ฃผ๋‹ˆ์–ด ์„ฑ์žฅ์ผ๊ธฐ: 2021.05.01
Post
Cancel

๐Ÿฅ ์ฃผ๋‹ˆ์–ด ์„ฑ์žฅ์ผ๊ธฐ: 2021.05.01

๐Ÿˆ Catchoo ํ”„๋กœ์ ํŠธ

  • record ์กฐํšŒ ์‹œ ๋ฆฌํ„ด๋˜๋Š” ๋ฐ์ดํ„ฐ ๋ณ€๊ฒฝ: catId ์‚ญ์ œ, commentId ์‚ฝ์ž…
  • ์ „์ฒด์ ์œผ๋กœ ์ˆ˜์ •๊ณผ ์‚ญ์ œ ๋ฒ„๊ทธ ์žก์Œ
  • ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ ์‹œ ์‚ญ์ œ๋œ ๋Œ“๊ธ€ ๋‚˜์˜ค๋Š” ๋ฌธ์ œ ์ˆ˜์ •
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

REPOSITORY=/home/admin/app/step1/Project_Cats

cd $REPOSITORY/catchoo-server/

echo "> Git Pull"

git pull

echo "> project build start"

./gradlew build

echo "> copy Build file"

cp ./build/libs/*.jar $REPOSITORY/

echo "> check pid of application running now"

CURRENT_PID=$(pgrep -f cat-app-server)

echo "$CURRENT_PID"

if [ -z $CURRENT_PID ]; then
    echo "> not shut down because there is not application running now."
else
    echo "> kill -2 $CURRENT_PID"
    kill -9 $CURRENT_PID
    sleep 5
fi

echo "> deploy new application"

JAR_NAME=$(ls $REPOSITORY/ |grep 'cat-app-server' | tail -n 1)

echo "> JAR Name: $JAR_NAME"

nohup java -jar $REPOSITORY/$JAR_NAME &
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ArticleService.java 
public List<ArticleResponse> fetchArticlePagesBy(
  Long lastArticleId, int size, Long loginMemberId
) { 
  Member loginMember = memberService.findById(loginMemberId); // ์‚ฌ์šฉ์ž ๊ฐ์ฒด๋ฅผ ์กฐํšŒํ•œ๋‹ค.
  List<Member> followers = findFollowersWithLoggedInMember(loginMemberId, loginMember); // ์‚ฌ์šฉ์ž๋ฅผ ํฌํ•จํ•˜๊ณ , ์‚ฌ์šฉ์ž๊ฐ€ ํŒ”๋กœ์šฐํ•˜๊ณ  ์žˆ๋Š” ์‚ฌ๋žŒ๋“ค์„ ๊ฐ€์ ธ์˜จ๋‹ค. 
  Page<Article> articles = fetchPages(lastArticleId, size, followers); // followers์˜ ๊ฒŒ์‹œ๋ฌผ๋“ค์„ ํŽ˜์ด์ง€๋„ค์ด์…˜ํ•ด์„œ ๊ฐ€์ ธ์˜จ๋‹ค. 
  return ArticleAssembler.toDtos(articles.getContent(), loginMember); 
} 

private List<Member> findFollowersWithLoggedInMember(
  Long memberId, Member loginMember
) { 
  List<Long> followingsIds = followService.findFollowingsIds(memberId); 
  List<Member> allMembers = memberService.findAllByIds(followingsIds); 
  allMembers.add(loginMember); 
  return allMembers; 
} 

private Page<Article> fetchPages(Long lastArticleId, int size, List<Member> followers) { 
  PageRequest pageRequest = PageRequest.of(0, size); // ํŽ˜์ด์ง€๋„ค์ด์…˜์„ ์œ„ํ•œ PageRequest, ํŽ˜์ด์ง€๋Š” 0์œผ๋กœ ๊ณ ์ •ํ•œ๋‹ค. 
  return articleRepository.findByIdLessThanAndAuthorInOrderByIdDesc(lastArticleId, followers, pageRequest); // JPA ์ฟผ๋ฆฌ ๋ฉ”์†Œ๋“œ 
}

๐Ÿ‘ฉโ€๐Ÿ’ป ๋ชจ๊ฐ์ฝ”

  • ํฌ์ง„์ด๋ž‘ ์˜ค๋žœ๋งŒ์— ํ•™๊ต ์•ž์—์„œ ๋ชจ๊ฐ์ฝ”

๐Ÿˆ Catchoo ํ”„๋กœ์ ํŠธ

๐Ÿ  JIB ํ”„๋กœ์ ํŠธ

ํ”„๋กœ์ ํŠธ์žฅ๋‹˜์ด ๊ทธ์ €๊ป˜ ๋‚ด ์„ฑ์žฅ์ผ๊ธฐ๋ฅผ ๋ณด์‹œ๊ณ  ๋ฆฌ์•กํŠธ ๋Šฅ๋ ฅ์ž์ธ ์ค„ ์•Œ๊ณ  ์—ฐ๋ฝ์„ ์ฃผ์…จ๋‹ค.. ํ•˜ํ•˜ํ•˜ ์ œ๊ฐ€ ๋ฆฌ์•กํŠธ ๋Šฅ๋ ฅ์ž์ธ์ค„ ์•„์…จ๋‹ค๋ฉด ๊ฒฝ๊ธฐ๋„ ์˜ค์‚ฐ์ž…๋‹ˆ๋‹ค ๊ทธ์ €๊ป˜ ์„ฑ์žฅ์ผ๊ธฐ์˜ ํ”„๋ก ํŠธ์—”๋“œ ํŒŒํŠธ๋Š” ๋ฆฌ์•กํŠธ ๋Šฅ๋ ฅ์ž์ธ ์บฃ์ธ„ ํŒ€์›๋ถ„๋“ค์ด ํ•˜์‹  ๋‚ด์šฉ์„ ์ •๋ฆฌํ•œ ๊ฒƒ..ใ…Žใ…Ž ์„ ์„ค๋ช…๋“œ๋ฆฌ๋‹ˆ๊นŒ ๊ทธ๋ž˜๋„ ์ผ๋‹จ ์ด๋ ‡๊ฒŒ ๋œ๊ฑฐ ํ”„๋ก ํŠธ์—”๋“œ๋„ ํ•ด๋ณด์ž! ํ•ด์„œ ์–ผ๋–จ๊ฒฐ์— ํ”„๋ก ํŠธ ํšŒ์˜๋„ ์ฐธ์„ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. ๋‘˜๋‹ค ํ•˜๋ฉด ์ •๋ง ์ข‹๊ฒ ์ง€๋งŒ ์ •๋ง ํ•  ์ˆ˜ ์žˆ๋Š”์ง€๋Š” ์ข€ ๋” ๋ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๋‹ค.

ํ”„๋ก ํŠธ์—”๋“œ ํšŒ์˜

  • ๋ฆฌ์•กํŠธ ํ”„๋กœ์ ํŠธ๋Š” ์ปดํฌ๋„ŒํŠธ๋กœ ๋‚˜๋ˆ„๋Š” ๊ฒƒ์—์„œ ์‹œ์ž‘ํ•œ๋‹ค. ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ฆฌ์•กํŠธ์˜ ๊ฐ€์žฅ ํ•ต์‹ฌ

  • ๋ณดํ†ต ํ”„๋ก ํŠธ์—์„œ ๋Œ€๊ฐ• ํ™”๋ฉด ๋ฐ ๋ผ์ธ์„ ์ฃผ๋ฉด ๊ธฐํšํŒ€์—์„œ ์ด๋ฅผ ์ฑ„์›Œ๋„ฃ๋Š” ์‹์œผ๋กœ ํ”„๋กœ์ ํŠธ๊ฐ€ ์‹œ์ž‘ํ•œ๋‹ค๊ณ  ํ•˜์…จ๋‹ค. ๋ฐฑ์—”๋“œ๋Š” ์ด๊ฒŒ ๋‚˜์™”์„ ๋•Œ ์ข€ ๋‚˜์ค‘์— ์‹œ์ž‘ํ•œ๋‹ค๊ณ .. ์ด ์ด์•ผ๊ธฐ๋ฅผ ๋“ค์œผ๋ฉฐ ์•„๋ฌด ์ƒ๊ฐ ์—†์ด ๋ฐฑ์—”๋“œ์—์„œ ๋ฐ์ดํ„ฐ ์Šคํ‚ค๋งˆ๋ถ€ํ„ฐ ํ™”๋ฉด์ด ์–ด๋–ป๊ฒŒ ๋‚˜์˜ฌ ์ง€ ๋‹ค ์˜ˆ์ธกํ•˜๊ณ  ์ •ํ•ด์„œ ์‹œ์ž‘์„ ํ–ˆ๋˜ ์บฃ์ธ„ ํ”„๋กœ์ ํŠธ๊ฐ€ ์ƒ๊ฐ๋‚˜๋ฉด์„œ.. ๋ˆˆ๋ฌผ์„ ํ›”์ณค๋‹ค..

  • ๊ธฐํšํŒ€์—์„œ ์ž‘์„ฑํ•œ ํ”Œ๋กœ์šฐ๋ฅผ ๋”ฐ๋ผ๊ฐ€๋ฉด์„œ ๋น„์ฆˆ๋‹ˆ์Šค ์ดํ•ด๋ฅผ ํ•˜๋Š” ์‹œ๊ฐ„์„ ๊ฐ€์กŒ๋‹ค.

  • Class Component๊ฐ€ ์•„๋‹Œ Functional Component๋ฅผ ์‚ฌ์šฉํ•  ๊ฑฐ๋ผ๊ณ  ์ •ํ•ด์กŒ๋‹ค.

    • Functional Component๊ฐ€ ๋ณด๋‹ค Class ๋ฐฉ์‹๋ณด๋‹ค ์ข€ ๋” ๊ฐ„๋‹จํ•˜๊ณ , ์š”์ฆ˜ ํŠธ๋ Œ๋“œ๋ผ๊ณ  ํ•œ๋‹ค. Class ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ์ƒ์„ฑ์ž๋„ ์‚ฌ์šฉํ•˜๊ณ , ComponentDidMount, Update, Delete ๋ชจ๋‘ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋ฉฐ render()๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ฝ”๋“œ์— ์ž‘์„ฑํ•ด์•ผ ํ•œ๋‹ค. Functional ๋ฐฉ์‹์˜ ๊ฒฝ์šฐ ์ด ๋ชจ๋“  ๊ฒƒ๋“ค์ด ๋น„ํ•˜์ธ๋“œ ์”ฌ์—์„œ ์ผ์–ด๋‚œ๋‹ค๊ณ  ํ•œ๋‹ค.
    • ์ž๋ฐ”๋กœ ๊ฐœ๋ฐœ์„ ์‹œ์ž‘ํ•˜๊ณ  ํ˜„์žฌ์ง„ํ–‰ํ˜•์œผ๋กœ ์ž๋ฐ”๊ฐœ๋ฐœ์ž๋กœ ๊ฐœ๋ฐœํ•˜๊ณ  ์žˆ๋Š” ๋‚˜๋กœ์„œ๋Š” ํด๋ž˜์Šค ๋ฌธ๋ฒ•์ด ๋” ์ง๊ด€์ ์ด๋ผ๊ณ  ๋Š๊ปด์ง€์ง€๋งŒ.. ๊ทธ๋ž˜๋„ ๋น„ํ•˜์ธ๋“œ ์”ฌ์—์„œ ์ด๋ฃจ์–ด์ง€๋‹ˆ ์ƒ์‚ฐ์„ฑ๊ณผ ๊ฐ€๋…์„ฑ์€ ํ–ฅ์ƒ๋  ๊ฒƒ ๊ฐ™๋‹ค.
    • ์‹ค์ œ๋กœ ํ•จ์ˆ˜ํ˜•์€ ํด๋ž˜์Šค๋ณด๋‹ค ํ›„์— ๋‚˜์™”๊ธฐ์— ๋” ํŽธํ•˜๋‹ค๊ณ  ํ•œ๋‹ค. ํ•จ์ˆ˜ํ˜•์€ state, lifeCycle ๊ด€๋ จ ๊ธฐ๋Šฅ์€ ์‚ฌ์šฉ ๋ถˆ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ์ด๋Š” Hook์„ ํ†ตํ•ด ํ•ด๊ฒฐ๋œ๋‹ค๊ณ  ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํด๋ž˜์Šคํ˜•๋ณด๋‹ค ๋ฉ”๋ชจ๋ฆฌ ์ž์›์„ ๋œ ์‚ฌ์šฉํ•œ๋‹ค. ๋˜ํ•œ ์ปดํฌ๋„ŒํŠธ ์„ ์–ธ์ด ํŽธํ•˜๋‹ค๋Š” ์žฅ์ ์ด ์žˆ๋‹ค. ๋‹จ ์ž„์˜ ๋ฉ”์„œ๋“œ๋Š” ์ •์˜ํ•  ์ˆ˜๋Š” ์—†๋‹ค.
    • ํด๋ž˜์Šคํ˜•๊ณผ ํ•จ์ˆ˜ํ˜• ์ฐจ์ด
  • ๊ทธ๋ฆฌ๊ณ  ๋Œ€์žฅ๋‹˜์ด ๋ฆฌ์•กํŠธ LifeCycle์ด ์ค‘์š”ํ•˜๋‹ค๋ฉด์„œ ์„ค๋ช…ํ•ด์ฃผ์…จ๋‹ค.

    image

    ์ถœ์ฒ˜: https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/

    • Mount(์ƒ์„ฑ): ์ปดํฌ๋„ŒํŠธ์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋˜์–ด, DOM์— ์‚ฝ์ž…๋  ๋•Œ ์ˆœ์„œ๋Œ€๋กœ ํ˜ธ์ถœ๋œ๋‹ค.
      • constructor()
      • render()
      • componentDidMount()
    • Update: props๋‚˜ state๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด render(๊ฐฑ์‹ )๊ฐ€ ์ง„ํ–‰๋˜๋ฉฐ ์ˆœ์„œ๋Œ€๋กœ ํ˜ธ์ถœ๋œ๋‹ค.
      • render()
      • componentDidUpdate()
    • Unmount: ์ปดํฌ๋„ŒํŠธ๊ฐ€ DOM์—์„œ ์ œ๊ฑฐ๋  ๋•Œ ํ˜ธ์ถœ๋œ๋‹ค.
      • componentWillUnmount()

    ๋œฌ๊ธˆ์—†์ด ์Šคํ”„๋ง ๋นˆ ์ƒ๋ช…์ฃผ๊ธฐ๊ฐ€ ์ƒ๊ฐ๋‚ฌ๋‹ค

  • ๊ณผ์ œ: ๋ฆฌ์•กํŠธ ์‚ฌ์šฉํ•ด์„œ JIB์˜ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ํŽ˜์ด์ง€ ๊ตฌํ˜„

๋ฐฑ์—”๋“œ์—”๋“œ ํšŒ์˜

  • DB ๊ฒฐ์ •
    • NoSQL(MongoDB): ์กฐํšŒ ์„ฑ๋Šฅ์ด ์ข‹๋‹ค.
    • SQL + Redis: RDB๋Š” ์กฐํšŒ ์„ฑ๋Šฅ์ด ์•ˆ์ข‹๊ธฐ ๋•Œ๋ฌธ์— Redis๋ฅผ ์ ์ ˆํžˆ ์‚ฌ์šฉํ•ด ์กฐํšŒ ๊ฒฐ๊ณผ๋ฅผ ์บ์‹ฑํ•ด ์„ฑ๋Šฅ์„ ๋†’์ผ ํ•„์š”๊ฐ€ ์žˆ๋‹ค.
  • ์˜์†์„ฑ ํ”„๋ ˆ์ž„์›Œํฌ(Persistance Framework)
    • MongoDB๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ, JPA์ฒ˜๋Ÿผ ์ธํ„ฐํŽ˜์ด์Šค ์„ ์–ธ๋งŒ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ์— ๊ฐ„๋‹จํ•˜๋‹ค.
    • SQL์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ JPA๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค.
  • ๋ชฉํ‘œ
    • ํ…Œ์ŠคํŠธ ์ฃผ๋„ ๊ฐœ๋ฐœ(TDD)
    • ํ™•์žฅ์„ฑ ์žˆ๋Š”(Scaleable) ๊ฐœ๋ฐœ
This post is licensed under CC BY 4.0 by the author.

๐Ÿฅ ์ฃผ๋‹ˆ์–ด ์„ฑ์žฅ์ผ๊ธฐ: 2021.04.28

๐Ÿฅ ์ฃผ๋‹ˆ์–ด ์„ฑ์žฅ์ผ๊ธฐ: 2021.05.01

Loading comments from Disqus ...