Skip to content

Commit 5f3fb03

Browse files
committed
✨ PagingDataSource 캐싱 처리
1 parent 8dd181d commit 5f3fb03

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

data/src/main/java/com/whyranoid/data/post/PostRepositoryImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class PostRepositoryImpl @Inject constructor(
2323
}.flow.cachedIn(coroutineScope)
2424
}
2525

26-
override fun getMyPagingPosts(uid: String): Flow<PagingData<Post>> {
26+
override fun getMyPagingPosts(uid: String, coroutineScope: CoroutineScope): Flow<PagingData<Post>> {
2727
return Pager(
2828
PagingConfig(pageSize = 5)
2929
) {
3030
PostPagingDataSource(myUid = uid, postDataSource)
31-
}.flow
31+
}.flow.cachedIn(coroutineScope)
3232
}
3333

3434
override fun getAllPostFlow(): Flow<List<Post>> {

domain/src/main/java/com/whyranoid/domain/repository/PostRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface PostRepository {
1111
// 글(홍보 / 인증) 페이징으로 가져오기 - 리모트
1212
fun getPagingPosts(coroutineScope: CoroutineScope): Flow<PagingData<Post>>
1313

14-
fun getMyPagingPosts(uid: String): Flow<PagingData<Post>>
14+
fun getMyPagingPosts(uid: String, coroutineScope: CoroutineScope): Flow<PagingData<Post>>
1515

1616
fun getAllPostFlow(): Flow<List<Post>>
1717

domain/src/main/java/com/whyranoid/domain/usecase/GetMyPagingPostsUseCase.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.paging.PagingData
44
import com.whyranoid.domain.model.Post
55
import com.whyranoid.domain.repository.AccountRepository
66
import com.whyranoid.domain.repository.PostRepository
7+
import kotlinx.coroutines.CoroutineScope
78
import kotlinx.coroutines.flow.Flow
89
import javax.inject.Inject
910

@@ -12,7 +13,7 @@ class GetMyPagingPostsUseCase @Inject constructor(
1213
private val postRepository: PostRepository
1314
) {
1415

15-
suspend operator fun invoke(): Flow<PagingData<Post>> {
16-
return postRepository.getMyPagingPosts(accountRepository.getUid())
16+
suspend operator fun invoke(coroutineScope: CoroutineScope): Flow<PagingData<Post>> {
17+
return postRepository.getMyPagingPosts(accountRepository.getUid(), coroutineScope)
1718
}
1819
}

presentation/src/main/java/com/whyranoid/presentation/community/CommunityItemFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ internal class CommunityItemFragment :
181181
}
182182

183183
viewLifecycleOwner.repeatWhenUiStarted {
184-
viewModel.getMyPagingPostsUseCase().collectLatest { myPostList ->
184+
viewModel.getMyPagingPostsUseCase(viewLifecycleOwner.lifecycleScope).collectLatest { myPostList ->
185185
postAdapter.submitData(myPostList)
186186
}
187187
}

0 commit comments

Comments
 (0)