Skip to content

Commit

Permalink
#18: DiscogsCollectionImporter.importDiscogsItems() now imports only …
Browse files Browse the repository at this point in the history
…the master folder's items.
  • Loading branch information
jrtibbetts committed May 1, 2019
1 parent b82e2de commit eda00b7
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public class DiscogsCollectionImporter: NSManagedObjectContext {
return importDiscogsCustomFields(forUserName: userName).then { (coreDataFields) -> Promise<CoreDataFoldersByID> in
self.importDiscogsFolders(forUserName: userName)
}.done { (coreDataFolders) in
self.importDiscogsItems(forUserName: userName)
guard let masterFolder = coreDataFolders[Int64(0)] else {
throw ImportError.noAllFolderWasFound
}

self.importDiscogsItems(forUserName: userName, inMasterFolder: masterFolder)
}
}

Expand Down Expand Up @@ -98,26 +102,22 @@ public class DiscogsCollectionImporter: NSManagedObjectContext {
}
}

private func buildListOfDiscogsItems(forUserName userName: String,
inMasterFolder masterFolder: Folder,
fromDiscogsFolder discogsFolder: SwiftDiscogs.CollectionFolder) {
let count = discogsFolder.count
private func importDiscogsItems(forUserName userName: String,
inMasterFolder masterFolder: Folder) {
let count = Int(masterFolder.expectedItemCount)
let pageSize = 100
let pageCount = (count / pageSize) + 1
let folderID = Int(masterFolder.folderID)

(1..<pageCount).forEach { (pageNumber) in
DiscogsManager.discogs.collectionItems(inFolderID: discogsFolder.id,
DiscogsManager.discogs.collectionItems(inFolderID: folderID,
userName: userName,
pageNumber: pageNumber,
resultsPerPage: pageSize).done { (itemsResult) in
}.cauterize()
}.cauterize()
}
}

private func importDiscogsItems(forUserName userName: String) {

}

}

public extension SwiftDiscogsApp.CollectionItem {
Expand Down Expand Up @@ -163,6 +163,7 @@ public extension SwiftDiscogsApp.Folder {
func update(withDiscogsFolder discogsFolder: SwiftDiscogs.CollectionFolder) {
self.folderID = Int64(discogsFolder.id)
self.name = discogsFolder.name
self.expectedItemCount = Int64(discogsFolder.count)
}

}
Expand Down

0 comments on commit eda00b7

Please sign in to comment.