-
Notifications
You must be signed in to change notification settings - Fork 8
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
[AN/USER] 축제 목록 캐싱 적용 (#591) #592
Conversation
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.
고생 많으셨습니다! 코멘트 확인해주세요!
|
||
interface FestivalRepository { | ||
val festivals: Flow<List<Festival>> | ||
|
||
suspend fun loadFestivals(): Result<List<Festival>> |
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.
실패 처리만 하고있어서 Result 만 반환해도 될 것 같네요
_uiState.value = FestivalListUiState.Success( | ||
festivals = it.map { festival -> | ||
FestivalItemUiState( | ||
id = festival.id, | ||
name = festival.name, | ||
startDate = festival.startDate, | ||
endDate = festival.endDate, | ||
thumbnail = festival.thumbnail, | ||
onFestivalDetail = ::showTicketReserve, | ||
) |
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.
개인적으로 private 함수로 분리했으면 좋겠습니당
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.
고생하셨습니다! 코멘트 남겼어용
override val festivals: Flow<List<Festival>> | ||
get() = festivalDao.getFestivals().transform { emit(it.toDomain()) } | ||
|
||
override suspend fun loadFestivals(): Result<List<Festival>> = | ||
runCatchingResponse { festivalRetrofitService.getFestivals() } | ||
.onSuccessOrCatch { it.toDomain() } | ||
.onSuccessOrCatch { festivals -> | ||
festivals.toDomain().also { | ||
CoroutineScope(Dispatchers.IO).launch { | ||
festivalDao.replaceFestivals(it.toEntity()) | ||
} | ||
} | ||
} |
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.
서버에 새 데이터를 요청해서 불러오는 동안에 캐싱해둔 데이터를 보여줄 수 있고 좋네요 👍
(몰라서 하는 질문) 매번 내장 DB 테이블 전체를 Delete하고 Insert 하는 건 성능상 문제가 없나요??
festivalRepository.loadFestivals().onFailure { | ||
_uiState.value = FestivalListUiState.Error | ||
analyticsHelper.logNetworkFailure( | ||
KEY_LOAD_FESTIVALS_LOG, | ||
it.message.toString(), | ||
) | ||
} |
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.
Room 써서 캐싱까지 할거면 Error 상태일 때도 캐싱된 데이터를 보여주면 좋을 것 같은데 이 부분 상태나 이벤트 처리 어떻게 할지 얘기 해봐야할 것 같아요!
불필요 브랜치를 삭제하다가 삭제해버렸네요. 죄송합니다! |
📌 관련 이슈
✨ PR 세부 내용
val festivals
을 추가하여 값을 Flow형태로 받아올 수 있게도 변경했습니다. 해당 구조에 대해서 피드백을 원합니다.