Skip to content

Commit

Permalink
Merge pull request #75 from Hooking-CEOS/feature/brand
Browse files Browse the repository at this point in the history
[feat] 성능 최적화
  • Loading branch information
CYJhub authored Jul 25, 2023
2 parents b608bc9 + dcbaf24 commit 3dc4685
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()


.antMatchers("**/oath-processor/**","/kakaologin","/copy", "/copy/search","/copy/filter","/copy/crawling", "/brand", "/brand/{brand_id}","/example/login"
.antMatchers("**/oath-processor/**","/kakaologin","/copy/{index}", "/copy/search","/copy/filter","/copy/crawling", "/brand", "/brand/{brand_id}","/example/login"

).permitAll()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request
List<CopyRes> textCopyRes = new ArrayList<>();
List<CopyRes> brandCopyRes = new ArrayList<>();

textCopyRes = copyService.selectCopyByQuery(q);
textCopyRes = cardJpaRepository.searchCopy(q);

if (moodType != null) {
moodCopyRes = copyService.selectMoodByQuery(q);
moodCopyRes = cardJpaRepository.searchMood(q);
setScrapCntWhenTokenNotProvided(httpRequest, moodCopyRes);
Collections.shuffle(moodCopyRes);
CopySearchResult moodResult = createCopySearchResult(moodCopyRes);
Expand All @@ -116,7 +116,7 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request
results.add(copyResult);
}
} else if (BrandType.containsKeyword(q)) {
brandCopyRes = copyService.selectBrandByQuery(q);
brandCopyRes = cardJpaRepository.searchBrand(q);
setScrapCntWhenTokenNotProvided(httpRequest, brandCopyRes);
Collections.shuffle(brandCopyRes);
CopySearchResult brandResult = createCopySearchResult(brandCopyRes);
Expand Down Expand Up @@ -212,7 +212,7 @@ public HttpRes<String> saveCrawling(@RequestBody CrawlingReq crawlingReq) {

@GetMapping("/filter")
public HttpRes<List<CopyRes>> searchFilterCard(HttpServletRequest httpRequest,CardSearchCondition condition) {
List<CopyRes> results = cardJpaRepository.search(condition);
List<CopyRes> results = cardJpaRepository.filter(condition);
List<CopyRes> limitedResults = getLimitedCopyRes(results,30);
setScrapCntWhenTokenNotProvided(httpRequest, limitedResults);
return new HttpRes<>(limitedResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.stereotype.Repository;
import shop.hooking.hooking.dto.CardSearchCondition;
import shop.hooking.hooking.dto.response.CopyRes;
import shop.hooking.hooking.dto.response.CopySearchResponse;
import shop.hooking.hooking.dto.response.QCopyRes;
import shop.hooking.hooking.entity.*;

Expand All @@ -26,7 +27,7 @@ public CardJpaRepository(EntityManager em) {
this.queryFactory = new JPAQueryFactory(em);
}

public List<CopyRes> search(CardSearchCondition condition){
public List<CopyRes> filter(CardSearchCondition condition){

String moodString = condition.getMood();
String[] moods = null;
Expand Down Expand Up @@ -127,4 +128,55 @@ private BooleanExpression priceEq(String[] prices) {
return priceExpression;
}


public List<CopyRes> searchMood(String q){
BooleanExpression moodNameEqualsQ = mood.moodName.eq(q);

return queryFactory
.selectDistinct(new QCopyRes(
card.id,
card.brand,
card.text,
card.scrapCnt,
card.createdAt))
.from(card)
.leftJoin(card.brand, brand)
.leftJoin(have)
.on(have.brand.eq(brand))
.join(have.mood, mood)
.where(moodNameEqualsQ)
.fetch();
}

public List<CopyRes> searchCopy(String q){
BooleanExpression textContainsQ = card.text.contains(q);

return queryFactory
.selectDistinct(new QCopyRes(
card.id,
card.brand,
card.text,
card.scrapCnt,
card.createdAt))
.from(card)
.where(textContainsQ)
.fetch();
}

public List<CopyRes> searchBrand(String q){
BooleanExpression brandContainsQ = brand.brandName.contains(q);

return queryFactory
.selectDistinct(new QCopyRes(
card.id,
card.brand,
card.text,
card.scrapCnt,
card.createdAt))
.from(card)
.leftJoin(card.brand, brand)
.where(brandContainsQ)
.fetch();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Repository
public interface CardRepository extends JpaRepository<Card, Long>{

List<Card> findTop5ByBrandIdOrderByCreatedAtDesc(Long brandId);
List<Card> findTop10ByBrandIdOrderByCreatedAtDesc(Long brandId);


Card findCardByBrandId(Long brandId); // 브랜드 아이디로 카피라이팅 카드 찾기
Expand Down

0 comments on commit 3dc4685

Please sign in to comment.