Skip to content

Commit

Permalink
fix(pagination): fix some calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Mar 10, 2023
1 parent 17bdfdb commit 1b11869
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
7 changes: 7 additions & 0 deletions Pocket.xcodeproj/xcshareddata/xcschemes/Pocket (iOS).xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
2 changes: 1 addition & 1 deletion PocketKit/Sources/Sync/Operations/FetchArchive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class FetchArchive: SyncOperation {
if case .started = initialDownloadState.value,
let totalCount = result.data?.user?.savedItems?.totalCount,
pagination.cursor == nil {
initialDownloadState.send(.paginating(totalCount: totalCount > pagination.maxItems ? pagination.maxItems : totalCount))
initialDownloadState.send(.paginating(totalCount: min(totalCount, pagination.maxItems)))
}

try await updateLocalStorage(result: result)
Expand Down
2 changes: 1 addition & 1 deletion PocketKit/Sources/Sync/Operations/FetchSaves.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class FetchSaves: SyncOperation {
if case .started = initialDownloadState.value,
let totalCount = result.data?.user?.savedItems?.totalCount,
pagination.cursor == nil {
initialDownloadState.send(.paginating(totalCount: totalCount > pagination.maxItems ? pagination.maxItems : totalCount))
initialDownloadState.send(.paginating(totalCount: min(totalCount, pagination.maxItems)))
}

try await updateLocalStorage(result: result)
Expand Down
4 changes: 2 additions & 2 deletions PocketKit/Sources/Sync/Operations/SyncTask.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation

enum SyncTask: Codable {
case fetchSaves(maxItems: Int)
case fetchArchive(maxItems: Int)
case fetchSaves
case fetchArchive
case favorite(remoteID: String)
case unfavorite(remoteID: String)
case delete(remoteID: String)
Expand Down
12 changes: 6 additions & 6 deletions PocketKit/Sources/Sync/PocketSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public class PocketSource: Source {

// MARK: - Saves/Archive items
extension PocketSource {
public func refreshSaves(maxItems: Int, completion: (() -> Void)? = nil) {
public func refreshSaves(completion: (() -> Void)? = nil) {
if lastRefresh.lastRefreshSaves == nil {
initialSavesDownloadState.send(.started)
}
Expand All @@ -218,10 +218,10 @@ extension PocketSource {
lastRefresh: lastRefresh
)

enqueue(operation: operation, task: .fetchSaves(maxItems: maxItems), completion: completion)
enqueue(operation: operation, task: .fetchSaves, completion: completion)
}

public func refreshArchive(maxItems: Int, completion: (() -> Void)? = nil) {
public func refreshArchive(completion: (() -> Void)? = nil) {
if lastRefresh.lastRefreshArchive == nil {
initialArchiveDownloadState.send(.started)
}
Expand All @@ -234,7 +234,7 @@ extension PocketSource {
lastRefresh: lastRefresh
)

enqueue(operation: operation, task: .fetchSaves(maxItems: maxItems), completion: completion)
enqueue(operation: operation, task: .fetchSaves, completion: completion)
}

public func favorite(item: SavedItem) {
Expand Down Expand Up @@ -514,7 +514,7 @@ extension PocketSource {
mutation: FavoriteItemMutation(itemID: remoteID)
)
enqueue(operation: operation, persistentTask: persistentTask)
case .fetchSaves(let maxItems):
case .fetchSaves:
let operation = operations.fetchSaves(
user: user,
apollo: apollo,
Expand All @@ -524,7 +524,7 @@ extension PocketSource {
lastRefresh: lastRefresh
)
enqueue(operation: operation, persistentTask: persistentTask)
case .fetchArchive(let maxItems):
case .fetchArchive:
let operation = operations.fetchArchive(
apollo: apollo,
space: space,
Expand Down
4 changes: 2 additions & 2 deletions PocketKit/Sources/Sync/Source+async.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extension Source {
public func refresh(maxItems: Int = 400) async {
public func refresh() async {
await withCheckedContinuation { (continuation: CheckedContinuation<Void, Never>) in
refreshSaves(maxItems: maxItems) {
refreshSaves {
continuation.resume(returning: ())
}
}
Expand Down
12 changes: 6 additions & 6 deletions PocketKit/Sources/Sync/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public protocol Source {

func object<T: NSManagedObject>(id: NSManagedObjectID) -> T?

func refreshSaves(maxItems: Int, completion: (() -> Void)?)
func refreshSaves(completion: (() -> Void)?)

func refreshArchive(maxItems: Int, completion: (() -> Void)?)
func refreshArchive(completion: (() -> Void)?)

func retryImmediately()

Expand Down Expand Up @@ -95,18 +95,18 @@ public protocol Source {

public extension Source {
func refreshSaves(completion: (() -> Void)?) {
self.refreshSaves(maxItems: SyncConstants.Saves.firstLoadMaxCount, completion: completion)
self.refreshSaves(completion: completion)
}

func refreshSaves() {
self.refreshSaves(maxItems: SyncConstants.Saves.firstLoadMaxCount, completion: nil)
self.refreshSaves(completion: nil)
}

func refreshArchive(completion: (() -> Void)?) {
self.refreshArchive(maxItems: SyncConstants.Archive.firstLoadMaxCount, completion: completion)
self.refreshArchive(completion: completion)
}

func refreshArchive() {
self.refreshArchive(maxItems: SyncConstants.Archive.firstLoadMaxCount, completion: nil)
self.refreshArchive(completion: nil)
}
}

0 comments on commit 1b11869

Please sign in to comment.