<commit_before>import Foundation
import SwiftUI
import MapKit
import Combine

public class FeedViewModel: ObservableObject {

    @ObservedObject var store = NSBrazilStore()
    private var cancellable: AnyCancellable? = nil

    public init() {
        fetchInfo()
    }

    func fetchInfo() {
        isLoading = true
        cancellable = store.fetchInfo()
            .receive(on: DispatchQueue.main)
            .sink(receiveCompletion: { received in
                switch received {
                case .finished:
                    print("sim")
                case .failure(_):
                    print("nao")
                    self.isEmpty = true
                }
            }, receiveValue: { value in
                self.isLoading = false
                self.homeFeed = value.feed.feedItems
                self.scheduleFeed = value.schedule.feedItems
            })
    }

    @Published var homeFeed: [FeedItem] = []
    @Published var scheduleFeed: [FeedItem] = []
    @Published var isEmpty: Bool = false
    @Published var isLoading: Bool = false
}
<commit_msg>Use cache publisher as fallback<commit_after>import Foundation
import SwiftUI
import MapKit
import Combine

public class FeedViewModel: ObservableObject {

    @ObservedObject var store = NSBrazilStore()
    private var cancellable: AnyCancellable? = nil

    public init() {
        fetchInfo()
    }

    func fetchInfo() {
        self.isLoading = true
        
        let cachePublisher = self.store.fetchCache()
        let networkPublisher = self.store.fetchInfo()
        
        self.cancellable?.cancel()
        self.cancellable = networkPublisher.catch({ _ in cachePublisher})
            .receive(on: DispatchQueue.main)
            .sink(receiveCompletion: { received in
                switch received {
                case .finished:
                    print("sim")
                case .failure(_):
                    print("nao")
                }
            }, receiveValue: { value in
                self.isLoading = false
                self.homeFeed = value.feed.feedItems
                self.scheduleFeed = value.schedule.feedItems
            })
    }

    @Published var homeFeed: [FeedItem] = []
    @Published var scheduleFeed: [FeedItem] = []
    @Published var isLoading: Bool = false
}

{'fraction_non_alphanumeric': 0.0847750865051903, 'fraction_numerical': 0.0, 'mean_word_length': 1.7700598802395209, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2355946', 'n_tokens_mistral': 625, 'n_tokens_neox': 564, 'n_words': 150}