Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent UI thread from blocking during batch upload #241

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
/// The queue on which most response handling is performed.
@property (nonatomic, readonly) NSOperationQueue *queue;

/// The queue on which we sleep until all processing is completed or the timeout is hit.
@property (nonatomic, readonly) NSOperationQueue *pollingQueue;

/// The dispatch group that pairs upload requests with upload responses so that we can wait for all request/response
/// pairs to complete before batch committing. In this way, we can start many upload requests (for files under the chunk
/// limit), without waiting for the corresponding response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ - (instancetype)initWithFileCommitInfo:(NSDictionary<NSURL *, DBFILESCommitInfo
// we specifiy a custom queue so that the main thread is not blocked
_queue = queue;
[_queue setMaxConcurrentOperationCount:1];

// create a special background queue to monitor progress and sleep until the processing is complete
_pollingQueue = [NSOperationQueue new];
[_pollingQueue setMaxConcurrentOperationCount:1];

// we want to make sure all of our file data has been uploaded
// before we make our final batch commit call to `/upload_session/finish_batch`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ - (void)queryJobStatus:(DBBatchUploadData *)uploadData asyncJobId:(NSString *)as
uploadData.responseBlock(nil, routeError, error, uploadData.fileUrlsToRequestErrors);
}];
}
}];
} queue:uploadData.pollingQueue];
}

- (NSUInteger)endBytesWithFileSize:(NSUInteger)fileSize startBytes:(NSUInteger)startBytes {
Expand Down Expand Up @@ -423,7 +423,7 @@ - (void)batchFinishUponCompletion:(DBBatchUploadData *)uploadData {
uploadData.responseBlock(nil, nil, error, uploadData.fileUrlsToRequestErrors);
}];
}
}];
} queue:uploadData.pollingQueue];
});
}

Expand Down