-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
038d3db
commit 0de2aad
Showing
21 changed files
with
480 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,17 +45,20 @@ jobs: | |
source: "./.env" | ||
target: "./" | ||
|
||
- name: ubuntu Docker image build and push | ||
run: | | ||
docker-compose build -f ./docker/docker-compose.yml | ||
docker-compose push -f ./docker/docker-compose.yml | ||
# - name: ubuntu Docker image build | ||
# run: docker build -t ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest -f Dockerfile-server . | ||
# | ||
# - name: Redis Docker image build | ||
# run: docker build -t ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis -f Dockerfile-redis . | ||
|
||
- name: ubuntu Docker image build | ||
run: docker build -t ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest -f Dockerfile-server . | ||
|
||
- name: Redis Docker image build | ||
run: docker build -t ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis -f Dockerfile-redis . | ||
|
||
- name: ubuntu docker Hub 푸쉬 | ||
run: docker push ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest | ||
- name: Redis docker Hub 푸쉬 | ||
run: docker push ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis | ||
# - name: ubuntu docker Hub 푸쉬 | ||
# run: docker push ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest | ||
# - name: Redis docker Hub 푸쉬 | ||
# run: docker push ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis | ||
|
||
- name: Deploy with push | ||
uses: appleboy/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: '3' | ||
services: | ||
server: | ||
build: | ||
context: ./ | ||
dockerfile: server/Dockerfile-server | ||
image: eunchannam/we-share-wish-hair:latest | ||
|
||
redis: | ||
build: | ||
context: ./ | ||
dockerfile: redis/Dockerfile-redis | ||
image: eunchannam/we-share-wish-hair:redis |
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions
9
src/main/java/com/inq/wishhair/wesharewishhair/global/config/SchedulerConfig.java
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
src/main/java/com/inq/wishhair/wesharewishhair/global/config/database/DataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.inq.wishhair.wesharewishhair.global.config.database; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
|
||
@Profile("dev") | ||
@Configuration | ||
public class DataSourceConfig { | ||
|
||
private static final String MASTER_DATASOURCE = "masterDataSource"; | ||
private static final String SLAVE_DATASOURCE = "slaveDataSource"; | ||
private static final String ROUTING_DATASOURCE = "slaveDataSource"; | ||
|
||
@Bean(MASTER_DATASOURCE) | ||
@ConfigurationProperties(prefix = "spring.datasource.master.hikari") | ||
public DataSource masterDataSource() { | ||
return DataSourceBuilder.create() | ||
.type(HikariDataSource.class) | ||
.build(); | ||
} | ||
|
||
@Bean(SLAVE_DATASOURCE) | ||
@ConfigurationProperties(prefix = "spring.datasource.slave.hikari") | ||
public DataSource slaveDataSource() { | ||
return DataSourceBuilder.create() | ||
.type(HikariDataSource.class) | ||
.build(); | ||
} | ||
|
||
@Bean(ROUTING_DATASOURCE) | ||
public DataSource routingDataSource( | ||
@Qualifier(MASTER_DATASOURCE) DataSource masterDataSource, | ||
@Qualifier(SLAVE_DATASOURCE) DataSource slaveDataSource | ||
) { | ||
RoutingDataSource routingDataSource = new RoutingDataSource(); | ||
|
||
Map<Object, Object> datasourceMap = new HashMap<>(); | ||
datasourceMap.put("master", masterDataSource); | ||
datasourceMap.put("slave", slaveDataSource); | ||
|
||
routingDataSource.setTargetDataSources(datasourceMap); | ||
routingDataSource.setDefaultTargetDataSource(masterDataSource); | ||
|
||
return routingDataSource; | ||
} | ||
|
||
@Bean | ||
@Primary | ||
public LazyConnectionDataSourceProxy dataSource( | ||
@Qualifier(ROUTING_DATASOURCE) DataSource routingDataSource | ||
){ | ||
return new LazyConnectionDataSourceProxy(routingDataSource); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/inq/wishhair/wesharewishhair/global/config/database/RoutingDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.inq.wishhair.wesharewishhair.global.config.database; | ||
|
||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; | ||
import org.springframework.transaction.support.TransactionSynchronizationManager; | ||
|
||
public class RoutingDataSource extends AbstractRoutingDataSource { | ||
|
||
@Override | ||
protected Object determineCurrentLookupKey() { | ||
return (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) ? "slave" : "master"; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewTestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.inq.wishhair.wesharewishhair.review.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.inq.wishhair.wesharewishhair.global.utils.RedisUtils; | ||
import com.inq.wishhair.wesharewishhair.review.domain.entity.Review; | ||
import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReview; | ||
import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReviewRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LikeReviewTestService { | ||
|
||
private final LikeReviewRepository likeReviewRepository; | ||
private final ReviewFindService reviewFindService; | ||
private final RedisUtils redisUtils; | ||
|
||
public long count(Long reviewId) { | ||
return likeReviewRepository.countByReviewId(reviewId); | ||
} | ||
|
||
public void clean() { | ||
likeReviewRepository.deleteAll(); | ||
} | ||
|
||
/** | ||
* LikeReview 생성 후 Review 에 락걸고 likeCount 변수 update | ||
*/ | ||
public void withLock(Long reviewId, Long userId) { | ||
likeReviewRepository.save(LikeReview.addLike(userId, reviewId)); | ||
|
||
Review review = reviewFindService.getWithLockById(reviewId); | ||
review.addLike(); | ||
} | ||
|
||
/** | ||
* 레디스에 좋아요 정보가 없으면 새로 등록하고 있으면 INCR 수행 | ||
*/ | ||
public void withoutLock(Long reviewId, Long userId) { | ||
likeReviewRepository.save(LikeReview.addLike(userId, reviewId)); | ||
|
||
redisUtils.getData(reviewId) | ||
.ifPresentOrElse( | ||
likeCount -> redisUtils.increaseData(reviewId), | ||
() -> { | ||
Long likeCount = likeReviewRepository.countByReviewId(reviewId); | ||
redisUtils.setData(reviewId, likeCount); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...main/java/com/inq/wishhair/wesharewishhair/review/infrastructure/ReviewQueryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.inq.wishhair.wesharewishhair.review.infrastructure; | ||
|
||
import com.inq.wishhair.wesharewishhair.review.domain.entity.Review; | ||
import com.querydsl.core.annotations.QueryProjection; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ReviewQueryResponse { | ||
|
||
private final Review review; | ||
private final long likes; | ||
|
||
@QueryProjection | ||
public ReviewQueryResponse(Review review, long likes) { | ||
this.review = review; | ||
this.likes = likes; | ||
} | ||
} |
Oops, something went wrong.