<commit_before>//
//  DefaultFeedsImporter.swift
//  Evergreen
//
//  Created by <NAME> on 8/13/15.
//  Copyright © 2015 Ranchero Software, LLC. All rights reserved.
//

import Foundation
import Data
import Account

typealias DiskFeedDictionary = [String: Any]

struct DefaultFeedsImporter {
	
	static func importIfNeeded(_ firstRun: Bool, account: Account) {
		
		if shouldImportDefaultFeeds(firstRun) {
			FeedsImporter.importFeeds(defaultFeeds(), account: account)
		}
	}
	
	private static func defaultFeeds() -> [DiskFeedDictionary] {
		
		let f = Bundle.main.path(forResource: "DefaultFeeds", ofType: "plist")!
		return NSArray(contentsOfFile: f)! as! [DiskFeedDictionary]
	}
	
	private static func shouldImportDefaultFeeds(_ isFirstRun: Bool) -> Bool {
		
		if !isFirstRun || AccountManager.shared.anyAccountHasAtLeastOneFeed() {
			return false
		}
		return true
	}
}

struct FeedsImporter {
	
	static func importFeeds(_ feedDictionaries: [DiskFeedDictionary], account: Account) {
		
		let feedsToImport = feeds(with: feedDictionaries, accountID: account.accountID)
		
		BatchUpdate.shared.perform {
			for feed in feedsToImport {
				if !account.hasFeed(with: feed.feedID) {
					let _ = account.addFeed(feed, to: nil)
				}
			}
		}
	}
	
	private static func feeds(with feedDictionaries: [DiskFeedDictionary], accountID: String) -> Set<Feed> {

		let feedArray = feedDictionaries.flatMap { Feed(accountID: accountID, dictionary: $0) }
		return Set(feedArray)
	}
}<commit_msg>Set account to dirty after importing feeds.<commit_after>//
//  DefaultFeedsImporter.swift
//  Evergreen
//
//  Created by <NAME> on 8/13/15.
//  Copyright © 2015 Ranchero Software, LLC. All rights reserved.
//

import Foundation
import Data
import Account

typealias DiskFeedDictionary = [String: Any]

struct DefaultFeedsImporter {
	
	static func importIfNeeded(_ firstRun: Bool, account: Account) {
		
		if shouldImportDefaultFeeds(firstRun) {
			FeedsImporter.importFeeds(defaultFeeds(), account: account)
		}
	}
	
	private static func defaultFeeds() -> [DiskFeedDictionary] {
		
		let f = Bundle.main.path(forResource: "DefaultFeeds", ofType: "plist")!
		return NSArray(contentsOfFile: f)! as! [DiskFeedDictionary]
	}
	
	private static func shouldImportDefaultFeeds(_ isFirstRun: Bool) -> Bool {
		
		if !isFirstRun || AccountManager.shared.anyAccountHasAtLeastOneFeed() {
			return false
		}
		return true
	}
}

struct FeedsImporter {
	
	static func importFeeds(_ feedDictionaries: [DiskFeedDictionary], account: Account) {
		
		let feedsToImport = feeds(with: feedDictionaries, accountID: account.accountID)
		
		BatchUpdate.shared.perform {
			for feed in feedsToImport {
				if !account.hasFeed(with: feed.feedID) {
					let _ = account.addFeed(feed, to: nil)
				}
			}
		}
		account.dirty = true
	}
	
	private static func feeds(with feedDictionaries: [DiskFeedDictionary], accountID: String) -> Set<Feed> {

		let feedArray = feedDictionaries.flatMap { Feed(accountID: accountID, dictionary: $0) }
		return Set(feedArray)
	}
}
{'fraction_non_alphanumeric': 0.1055941741145316, 'fraction_numerical': 0.006620324395895399, 'mean_word_length': 4.174657534246576, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '231037', 'n_tokens_mistral': 1089, 'n_tokens_neox': 924, 'n_words': 240}