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

Implements Local Sync Stats helper #362

Merged
merged 1 commit into from
Oct 1, 2014
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
1 change: 0 additions & 1 deletion Simperium/SPBucket+Internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ typedef void (^SPBucketForceSyncCompletion)(BOOL signatureUpdated);
- (BOOL)isForceSyncPending;
- (void)signalForceSyncComplete;
- (NSDictionary*)exportStatus;
- (NSInteger)numChangesPending;

@end
7 changes: 7 additions & 0 deletions Simperium/SPBucket.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,11 @@ typedef NS_ENUM(NSUInteger, SPBucketChangeType) {
- (NSInteger)numObjects;
- (NSInteger)numObjectsForPredicate:(NSPredicate *)predicate;

// Retrive Simperium's Sync'ing stats:
// - Local Pending Changes: Number of captured changes, pending to be sent / acknowledged
// - Local Enqueued Changes: Number of objects marked for further processing
// - Local Enqueued Deletions: Number of objects marked for deletion
typedef void(^SPBucketStatsCallback)(NSUInteger localPendingChanges, NSUInteger localEnqueuedChanges, NSUInteger localEnqueuedDeletions);
- (void)statsWithCallback:(SPBucketStatsCallback)callback;

@end
13 changes: 11 additions & 2 deletions Simperium/SPBucket.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,17 @@ - (NSInteger)numObjectsForPredicate:(NSPredicate *)predicate {
return [self.storage numObjectsForBucketName:self.name predicate:predicate];
}

- (NSInteger)numChangesPending {
return self.changeProcessor.numChangesPending;
- (void)statsWithCallback:(SPBucketStatsCallback)callback {
SPChangeProcessor *processor = self.changeProcessor;
dispatch_async(self.processorQueue, ^{
NSUInteger numPendingChanges = processor.numChangesPending;
NSUInteger numEnqueuedChanges = processor.numKeysForObjectsWithMoreChanges;
NSUInteger numEnqueuedDeletions = processor.numKeysForObjectToDelete;

dispatch_async(dispatch_get_main_queue(), ^{
callback(numPendingChanges, numEnqueuedChanges, numEnqueuedDeletions);
});
});
}

- (NSString *)lastChangeSignature {
Expand Down