-
반응형
우리 회사는 FireStore를 사용하는 중
FireStore는 pagenation을 지원하는데, 뭔가 잘 안되는 이슈가 있어서 해결방법까지 정리해보겠습니다.
이슈)
createdAt을 기준으로 pagenation을 구현할 때 start(after:) 를 사용하면 같은 값은 exclude라고 분명 문서에 나오고 있는데 createdAt이 동일한 아이템이 자꾸 나오는 문제가 있음
var ref = db.col(.Users).doc(userId).col(.Likes) .order(by: "createdAt", descending: true) .limit(to: limit) if let date = date { ref = ref.start(after: [date]) }
문제 파악 ) Likes 라는 Document를 Decode 할때 createAt을 Date 타입으로 디코딩 하고 있었다.
public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) userId = try container.decode(DocumentID<String>.self, forKey: .userId).wrappedValue createdAt = try container.decode(Date.self, forKey: .createdAt) }
이때 FireStore Timestamp -> Date 타입으로 바뀌게 되는데, 이게 바뀌게 되는것 자체는 별 문제가 아니지만 이걸 가지고 다시 query를 하는 것이 문제였다
해결) 다시 date -> Timestamp 타입으로 변경해서 쿼리하면 해결됩니다 ~! 에고 시간 너무 많이썼다
if let date = date { ref = ref.start(after: [Timestamp(date: date)]) }
반응형'개발' 카테고리의 다른 글
[Swift/iOS] Auto rolling CollectionView 구현하기 & 스냅 스크롤 구현하기 (0) 2022.11.02 Facebook Developer Trouble shooting (0) 2022.08.24 [iOS/WWDC] App Attest & Device Check (1) 2022.08.03 [Swift/iOS] UIPageControl 크래시 이슈 해결 (Page-out-of-bounds) (0) 2022.08.02 Nuke & CollectionView 이미지 프리로드하기 (0) 2022.07.20 댓글