Open
Conversation
+ misc: modify docker-compose.yml, application-dev.yml
- init jpa entity: UserV2, UserStatusV2, ChannelV2, BinaryContentV2, MessageV2, ReadStatusV2
- UserServiceDto: init UserDto, UserUpdateDto, UserCreateDto, UserUniquenessDto, UserResponse
- GlobalMapperConfig: init - BaseMapper: init - UserMapper: init
- UserService: command -> dto - BasicUserService: remove IdGenerator - BasicUserService: suspending 'find' because not including api specs - BasicUserService: convert entity <-> dto using mapper
- BasicDomainService: update - BaseMapper: update - BaseEntity: update - BaseUpdatableEntity: update
- dto: ChannelServiceDto split by self and several requestDto - Channel: update with jpa - ChannelMapper: init - ChannelService: refactoring - BasicChannelService: update corresponding to jpa repository - ChannelController: update using mapper
- Message: add update, constructor - MessageServiceDTO: split by requestDto and dto - MessageMapper: init - BasicMessageService: update using mapper, dto - MessageController: mapper used to convert several parameter into one dto
- BinaryContent: add constructor - BinaryContentServiceDto: init requestDto, dto - BinaryContentMapper: init - BasicBinaryContentService: using mapper - BinaryContentController:
… and init mapper - ReadStatus: add constructor, update - ReadStatusServiceDTO: split by requestDto and dto - ReadStatusMapper: init - ReadStatusRepository: add features about userId and channelId - BasicReadStatusService: update using mapper - ReadStatusController: convert requestDto to ReadStatusDto
- AuthServiceDTO: change annotation - UserRepository: add feature for auth - BasicAuthService: update login - AuthController: add Valid annotation
…entity - BasicUserStatusService: remove create, find, findAll, delete - UserStatusMapper: init - UserStatus: add constructor, update - UserStatusServiceDTO: update
- BinaryContentController: add download feature
- User: add constructor - UserDto: add constructor - UserFindRequest: removed - UserMapper: update toResponse, remove toDtoFrom*Request - UserService: remove extends DomainService - BasicUserService: add transaction - UserController: remove mappers
- build.gradle: add dependencies analysis, openfeign.QueryDSL - docker-compose.yml: db port 5432 -> 5433
To retrieve the 'lastMessageAt' of a 'channel', the associated 'Message' must be retrieved. This process causes the 'N+1 problem'. A simple solution would be to use a 'fetch join'. However, 'QueryDSL' was chosen to further improve performance. Querying a single 'Channel' alone used 2 'Query's. If this method were applied to query multiple 'Channels', it would generate N+N 'Query's, so a different approach was used to resolve this. Consequently, it was concluded that using 'Native SQL' is the best option.
- APIExceptionAdvice: rename handleIdNotFound -> handleAPIException - APIExceptionAdvice: add handleIncorrectInput - ErrorCode: add PRIVATE_CHANNEL_CANT_BE_UPDATED - TimeConverter: change LocalDateTime(deprecated) to LocalDate
- update entity: Message, ReadStatus, UserStatus - update dto: BinaryContentServiceDTO, MessageServiceDTO, UserStatusServiceDTO
- TimeMapper(util mapper): init - update: GlobalMapperConfig, BinaryContentMapper, ReadStatusMapper, UserMapper, UserStatusMapper
- dto: change LocalDateTime to LocalDate - controller: renaming
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
회고
사실 구현만 했고 테스트는 못해봤습니다.
구현 중 N+1 문제를 마주했고 해결 방법을 위해 많은 시간을 사용했습니다.
가장 쉬운 방법으로
Fetch Join이 있습니다.연관된 모든 entity 를 함께 가져옵니다.
하지만 pagination 을 사용할 수 없기에 다른 방법을 찾아봤습니다.
QueryDSL에 대해 공부했습니다.Joinsql 을 native 가 아닌 java code 로 구현할 수 있어서 편리합니다.예를 들어 entity field 를 refactoring 할 때 안전합니다.
전자는 messages table 를 먼저 group by 하고 channels 와 join 합니다.
index 를 많이 활용하므로 데이터가 많은 경우 성능이 더 좋습니다.
후자는 channel_id 마다 messages table 의 channel_id 와 비교 후 max_created_at 을 계산합니다.
데이터가 적다면 전자 보다 성능이 더 좋다라고 AI 가 말합니다.
전자를 QueryDSL 로 구현하고 싶었지만 하지 못했고 jdbcTemplate 으로 할 수 있다고 합니다.
성능도 더 좋습니다.
거기까지는 너무 멀리가는 것 같아 여기서 마무리 했습니다.
추후 시간이 된다면 반드시 마무리할 예정입니다.
더 좋은 방법은 없는지, 중복된 구조를 줄일 수 없는지, 적절한 이름 추천, ...
많은 도움을 받았지만 대부분 제가 만든 코드이며 어떻게 동작하는지 알고 있습니다.
이번 과제만 그런 것이 아니라 이전부터 그렇게 해왔습니다.
감사합니다.