-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
검색 쿼리 개선 #703
검색 쿼리 개선 #703
Changes from all commits
ae3c196
c158416
97c7c55
9bdcf8b
952a590
d0982d1
2bfbd27
deb779a
45458c1
cda1f3f
5918abb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -52,6 +52,17 @@ public List<Tag> findAllByTemplate(Template template) { | |||||||||
.toList(); | ||||||||||
} | ||||||||||
|
||||||||||
public List<Tag> findAllByTemplateId(Long templateId) { | ||||||||||
return templateTagRepository.findAllByTemplateId(templateId).stream() | ||||||||||
.map(TemplateTag::getTag) | ||||||||||
.toList(); | ||||||||||
} | ||||||||||
Comment on lines
+55
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나중에 Tag 를 받도록 변경하면 좋을 것 같아욧 ~ |
||||||||||
|
||||||||||
public List<TemplateTag> getAllTemplateTagsByTemplates(List<Template> templates) { | ||||||||||
List<Long> templateIds = templates.stream().map(Template::getId).toList(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
return templateTagRepository.findAllByTemplateIdsIn(templateIds); | ||||||||||
} | ||||||||||
|
||||||||||
public FindAllTagsResponse findAllByMemberId(Long memberId) { | ||||||||||
List<Template> templates = templateRepository.findByMemberId(memberId); | ||||||||||
List<Long> templateIds = templates.stream().map(Template::getId).toList(); | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
import jakarta.persistence.criteria.CriteriaBuilder; | ||
import jakarta.persistence.criteria.CriteriaQuery; | ||
import jakarta.persistence.criteria.JoinType; | ||
import jakarta.persistence.criteria.Predicate; | ||
import jakarta.persistence.criteria.Root; | ||
import jakarta.persistence.criteria.Subquery; | ||
|
@@ -37,6 +38,11 @@ public Predicate toPredicate(Root<Template> root, CriteriaQuery<?> query, Criter | |
addTagPredicate(predicates, criteriaBuilder, root, query); | ||
addKeywordPredicate(predicates, criteriaBuilder, root, query); | ||
|
||
if (query.getResultType().equals(Template.class)) { | ||
root.fetch("category", JoinType.LEFT); | ||
root.fetch("member", JoinType.LEFT); | ||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 추후 상수화 해요 ~ |
||
} | ||
|
||
return criteriaBuilder.and(predicates.toArray(new Predicate[0])); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,8 @@ public interface ThumbnailRepository { | |||||
|
||||||
List<Thumbnail> findAll(); | ||||||
|
||||||
List<Thumbnail> findAllByTemplateIn(List<Long> templateIds); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Thumbnail save(Thumbnail thumbnail); | ||||||
|
||||||
void deleteByTemplateId(Long id); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,14 @@ public Thumbnail getByTemplate(Template template) { | |
return thumbnailRepository.fetchByTemplate(template); | ||
} | ||
|
||
public List<Thumbnail> getAllByTemplates(List<Template> templates) { | ||
List<Long> templateIds = templates.stream() | ||
.map(Template::getId) | ||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 추후 id만 받도록 코드 개선하면 커버링 인덱스를 이용할 수 있을 것 같아요 ~ |
||
.toList(); | ||
|
||
return thumbnailRepository.findAllByTemplateIn(templateIds); | ||
} | ||
|
||
public ExploreTemplatesResponse findAll() { | ||
return ExploreTemplatesResponse.from(thumbnailRepository.findAll()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ | |||||
import codezap.tag.service.TagService; | ||||||
import codezap.template.domain.SourceCode; | ||||||
import codezap.template.domain.Template; | ||||||
import codezap.template.domain.TemplateTag; | ||||||
import codezap.template.domain.Thumbnail; | ||||||
import codezap.template.dto.request.CreateTemplateRequest; | ||||||
import codezap.template.dto.request.UpdateTemplateRequest; | ||||||
|
@@ -91,19 +92,43 @@ public FindAllTemplatesResponse findAllByWithMember( | |||||
} | ||||||
|
||||||
private FindAllTemplatesResponse makeResponse(Page<Template> page, LikedChecker likedChecker) { | ||||||
List<FindAllTemplateItemResponse> findAllTemplateByResponse = page.stream() | ||||||
.map(template -> FindAllTemplateItemResponse.of( | ||||||
template, | ||||||
tagService.findAllByTemplate(template), | ||||||
thumbnailService.getByTemplate(template).getSourceCode(), | ||||||
likedChecker.isLiked(template))) | ||||||
.toList(); | ||||||
List<Template> templates = page.getContent(); | ||||||
List<FindAllTemplateItemResponse> findAllTemplateByResponse = getFindAllTemplateItemResponses(templates, likedChecker); | ||||||
|
||||||
return new FindAllTemplatesResponse( | ||||||
page.getTotalPages(), | ||||||
page.getTotalElements(), | ||||||
findAllTemplateByResponse); | ||||||
} | ||||||
|
||||||
private List<FindAllTemplateItemResponse> getFindAllTemplateItemResponses(List<Template> templates, LikedChecker likedChecker) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
List<TemplateTag> allTemplateTagsByTemplates = tagService.getAllTemplateTagsByTemplates(templates); | ||||||
List<Thumbnail> allThumbnailsByTemplates = thumbnailService.getAllByTemplates(templates); | ||||||
|
||||||
return templates.stream() | ||||||
.map(template -> FindAllTemplateItemResponse.of( | ||||||
template, | ||||||
getTagByTemplate(allTemplateTagsByTemplates, template), | ||||||
getThumbnailSourceCodeByTemplate(allThumbnailsByTemplates, template), | ||||||
likedChecker.isLiked(template))) | ||||||
.toList(); | ||||||
} | ||||||
|
||||||
private List<Tag> getTagByTemplate(List<TemplateTag> templateTags, Template template) { | ||||||
return templateTags.stream() | ||||||
.filter(templateTag -> templateTag.hasTemplate(template)) | ||||||
.map(TemplateTag::getTag) | ||||||
.toList(); | ||||||
} | ||||||
|
||||||
private SourceCode getThumbnailSourceCodeByTemplate(List<Thumbnail> thumbnails, Template template) { | ||||||
return thumbnails.stream() | ||||||
.filter(thumbnail -> thumbnail.hasTemplate(template)) | ||||||
.findFirst() | ||||||
.map(Thumbnail::getSourceCode) | ||||||
.orElseGet(() -> thumbnailService.getByTemplate(template).getSourceCode()); | ||||||
} | ||||||
|
||||||
@Transactional | ||||||
public void update(Member member, Long templateId, UpdateTemplateRequest updateTemplateRequest) { | ||||||
Category category = categoryService.fetchById(updateTemplateRequest.categoryId()); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용되지 않는 메소드인 것 같네요.