2017-07-03 20:20:14 +02:00
|
|
|
//
|
2017-07-29 21:08:10 +02:00
|
|
|
// ArticlesTable.swift
|
2017-07-03 20:20:14 +02:00
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 5/9/16.
|
|
|
|
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2017-07-29 21:29:05 +02:00
|
|
|
import RSDatabase
|
2017-07-03 20:20:14 +02:00
|
|
|
import Data
|
|
|
|
|
2017-08-21 07:43:46 +02:00
|
|
|
//final class ArticlesTable: DatabaseTable {
|
|
|
|
//
|
|
|
|
// let name: String
|
|
|
|
// private let cachedArticles: NSMapTable<NSString, Article> = NSMapTable.weakToWeakObjects()
|
|
|
|
//
|
|
|
|
// init(name: String) {
|
|
|
|
//
|
|
|
|
// self.name = name
|
|
|
|
// }
|
2017-07-29 21:29:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-21 07:43:46 +02:00
|
|
|
// func uniquedArticles(_ fetchedArticles: Set<Article>, statusesTable: StatusesTable) -> Set<Article> {
|
|
|
|
//
|
|
|
|
// var articles = Set<Article>()
|
|
|
|
//
|
|
|
|
// for oneArticle in fetchedArticles {
|
|
|
|
//
|
|
|
|
// assert(oneArticle.status != nil)
|
|
|
|
//
|
|
|
|
// if let existingArticle = cachedArticle(oneArticle.databaseID) {
|
|
|
|
// articles.insert(existingArticle)
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// cacheArticle(oneArticle)
|
|
|
|
// articles.insert(oneArticle)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// statusesTable.attachCachedStatuses(articles)
|
|
|
|
//
|
|
|
|
// return articles
|
|
|
|
// }
|
2017-07-29 21:29:05 +02:00
|
|
|
|
2017-08-21 07:43:46 +02:00
|
|
|
// typealias FeedCountCallback = (Int) -> Void
|
|
|
|
//
|
|
|
|
// func numberOfArticlesWithFeedID(_ feedID: String, callback: @escaping FeedCountCallback) {
|
|
|
|
//
|
|
|
|
// queue.fetch { (database: FMDatabase!)
|
|
|
|
//
|
|
|
|
// let sql = "select count(*) from articles where feedID = ?;"
|
|
|
|
// var numberOfArticles = -1
|
|
|
|
//
|
|
|
|
// if let resultSet = database.executeQuery(sql, withArgumentsIn: [feedID]) {
|
|
|
|
//
|
|
|
|
// while (resultSet.next()) {
|
|
|
|
// numberOfArticles = resultSet.long(forColumnIndex: 0)
|
|
|
|
// break
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// DispatchQueue.main.async() {
|
|
|
|
// callback(numberOfArticles)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
//}
|
2017-07-29 21:29:05 +02:00
|
|
|
|
2017-08-21 07:43:46 +02:00
|
|
|
//private extension ArticlesTable {
|
2017-07-29 21:29:05 +02:00
|
|
|
|
2017-08-21 07:43:46 +02:00
|
|
|
// func cachedArticle(_ articleID: String) -> Article? {
|
|
|
|
//
|
|
|
|
// return cachedArticles.object(forKey: articleID as NSString)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// func cacheArticle(_ article: Article) {
|
|
|
|
//
|
|
|
|
// cachedArticles.setObject(article, forKey: article.databaseID as NSString)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// func cacheArticles(_ articles: Set<Article>) {
|
|
|
|
//
|
|
|
|
// articles.forEach { cacheArticle($0) }
|
|
|
|
// }
|
|
|
|
//}
|
2017-07-29 21:29:05 +02:00
|
|
|
|