Skip to content

[Refactor] CoreDataManager fetch 로직 개편 및 모델 속성 수정#53

Merged
jihyeonjjang merged 3 commits intodevfrom
feature/viewmodel-fetchedresults
Jun 13, 2025
Merged

[Refactor] CoreDataManager fetch 로직 개편 및 모델 속성 수정#53
jihyeonjjang merged 3 commits intodevfrom
feature/viewmodel-fetchedresults

Conversation

@jihyeonjjang
Copy link
Copy Markdown
Collaborator

@jihyeonjjang jihyeonjjang commented Jun 13, 2025

변경 내용

  • Video Entity에 thumbnailURL 속성 추가
  • TimeStamp Entity에서 사용하지 않는 endDate 속성 제거
  • CoreDataManager에서 NSFetchedResultsController 사용 제거
    • 기존 fetchedResults 제거 및 관련 메서드 삭제
    • fetch, fetch(tag:), fetchRecommended, fetchLiked, fetchHistory 메서드를 predicate 기반 직접 fetch로 대체
    • saveVideos에서 기존 cached object 접근 제거 → fetch 기반 비교로 변경
    • delete(by:) 또한 직접 fetch 방식으로 변경
  • 기존 FRC 방식이 필요한 경우를 대비해 makeVideoFRC() 메서드로 재사용 가능하게 구현

FRCFactory 사용 예제

var fetchedResultsController: NSFetchedResultsController<Video>

let predicate = NSPredicate(format: "isLiked == true") // history의 경우 (format: "timeStamp != nil AND timeStamp.startDate != nil")
let sort = [NSSortDescriptor(key: "id", ascending: false)] // history의 경우 key: "timeStamp.startDate"

fetchedResultsController = FRCFactory.makeVideoFRC(
    context: coreDataManager.mainContext, // 주입 받은 coreDataManager
    predicate: predicate,
    sortDescriptors: sort,
    delegate: self
)

fetchedResultsController.delegate = self
do {
    try fetchedResultsController.performFetch()
} catch {
    print("❌ fetch 실패: \(error.localizedDescription)")
}

…방식으로 변경

- 기존 fetchAll 기반 NSFetchedResultsController 로직 제거
- fetch(), fetch(tag:), fetchRecommended() 등 개별 fetch 함수 구현
- fetchLiked(), fetchHistory() 함수 정리 및 predicate 기반 단순 fetch 방식으로 변경
- saveVideos에서 기존 fetchedObjects 접근 제거 → fetch() 기반 데이터 비교로 수정
- update 로직에 thumbnailURL 비교 추가
- apply 함수에 thumbnailURL 및 새로운 타임스탬프 로직 반영
- delete(by:) 로직 개선: predicate 기반 직접 fetch로 삭제
- NSFetchedResultsController를 재사용할 수 있도록 makeVideoFRC 메서드 분리 구현
- updateTagScores 내부 계산에서, 시청 시간을 받아오도록 수정
@korbit-ai
Copy link
Copy Markdown

korbit-ai Bot commented Jun 13, 2025

You've used up your 5 PR reviews for this month under the Korbit Starter Plan. You'll get 5 more reviews on June 22nd, 2025 or you can upgrade to Pro for unlimited PR reviews and enhanced features in your Korbit Console.

<attribute name="downloads" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="id" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="isLiked" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="thumbnailURL" optional="YES" attributeType="String"/>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다

Copy link
Copy Markdown
Collaborator

@vinyl-nyl vinyl-nyl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다

Copy link
Copy Markdown
Collaborator

@giseungNoh giseungNoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다.

Copy link
Copy Markdown
Owner

@TeddKo TeddKo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@jihyeonjjang jihyeonjjang merged commit ff8cdf4 into dev Jun 13, 2025
@jihyeonjjang jihyeonjjang deleted the feature/viewmodel-fetchedresults branch June 13, 2025 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants