@@ -71,6 +71,13 @@ final class OrderListViewController: UIViewController {
7171 ///
7272 private let syncingCoordinator = SyncingCoordinator ( )
7373
74+ /// Timestamp for last successful sync.
75+ ///
76+ private var lastFullSyncTimestamp : Date ?
77+
78+ /// Minimum time interval allowed between full sync.
79+ ///
80+ private let minimalIntervalBetweenSync : TimeInterval = 30
7481
7582 /// UI Active State
7683 ///
@@ -144,7 +151,7 @@ final class OrderListViewController: UIViewController {
144151 override func viewWillAppear( _ animated: Bool ) {
145152 super. viewWillAppear ( animated)
146153
147- syncingCoordinator. resynchronize ( )
154+ syncingCoordinator. resynchronize ( reason : SyncReason . viewWillAppear . rawValue )
148155
149156 // Fix any incomplete animation of the refresh control
150157 // when switching tabs mid-animation
@@ -276,6 +283,15 @@ extension OrderListViewController: SyncingCoordinatorDelegate {
276283 /// Synchronizes the Orders for the Default Store (if any).
277284 ///
278285 func sync( pageNumber: Int , pageSize: Int , reason: String ? = nil , onCompletion: ( ( Bool ) -> Void ) ? = nil ) {
286+ if pageNumber == syncingCoordinator. pageFirstIndex,
287+ reason == SyncReason . viewWillAppear. rawValue,
288+ let lastFullSyncTimestamp = lastFullSyncTimestamp,
289+ Date ( ) . timeIntervalSince ( lastFullSyncTimestamp) < minimalIntervalBetweenSync {
290+ // less than 30 s from last full sync
291+ onCompletion ? ( true )
292+ return
293+ }
294+
279295 transitionToSyncingState ( )
280296 setErrorLoadingData ( to: false )
281297
@@ -292,6 +308,10 @@ extension OrderListViewController: SyncingCoordinatorDelegate {
292308 DDLogError ( " ⛔️ Error synchronizing orders: \( error) " )
293309 self . setErrorLoadingData ( to: true )
294310 } else {
311+ if pageNumber == self . syncingCoordinator. pageFirstIndex {
312+ // save timestamp of last successful update
313+ self . lastFullSyncTimestamp = Date ( )
314+ }
295315 ServiceLocator . analytics. track ( event: . ordersListLoaded( totalDuration: totalDuration,
296316 pageNumber: pageNumber,
297317 status: self . viewModel. statusFilter) )
0 commit comments