-
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
템플릿 생성, 수정 쿼리 성능 개선 #715
템플릿 생성, 수정 쿼리 성능 개선 #715
Changes from all commits
fb3d12b
f009c44
434502e
0f525fa
576b094
8280a69
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package codezap.tag.service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
@@ -25,25 +26,22 @@ public class TagService { | |
|
||
@Transactional | ||
public void createTags(Template template, List<String> tagNames) { | ||
List<String> existingTags = tagRepository.findNameByNamesIn(tagNames); | ||
templateTagRepository.saveAll( | ||
existingTags.stream() | ||
.map(tagRepository::fetchByName) | ||
.map(tag -> new TemplateTag(template, tag)) | ||
.toList() | ||
); | ||
List<Tag> existingTags = new ArrayList<>(tagRepository.findByNameIn(tagNames)); | ||
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. 방어적 복사를 하신건가요? 이유가 궁금 ~ 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.
|
||
List<String> existNames = existingTags.stream() | ||
.map(Tag::getName) | ||
.toList(); | ||
Comment on lines
+29
to
+32
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. 나중에 repository로 부터 name만 받도록 수정해서 커버링 인덱스를 사용해봐요 ~ |
||
|
||
List<Tag> newTags = tagRepository.saveAll( | ||
tagNames.stream() | ||
.filter(tagName -> !existingTags.contains(tagName)) | ||
.filter(name -> !existNames.contains(name)) | ||
.map(Tag::new) | ||
.toList() | ||
); | ||
templateTagRepository.saveAll( | ||
newTags.stream() | ||
.map(tag -> new TemplateTag(template, tag)) | ||
.toList() | ||
); | ||
existingTags.addAll(newTags); | ||
|
||
for (Tag existingTag : existingTags) { | ||
templateTagRepository.save(new TemplateTag(template, existingTag)); | ||
} | ||
} | ||
|
||
public List<Tag> findAllByTemplate(Template template) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE INDEX idx_tag_name ON tag(name); |
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.
다음에 테스트 추가해주세요~!!