Update commits every 0.1 sec instead of every 1000 commits

Slower machines will update more often and faster ones will do more work in each update.
This commit is contained in:
Nathan Kinsinger
2010-07-03 18:36:03 -06:00
parent 53d92fb73e
commit 7c62337ab9
2 changed files with 22 additions and 10 deletions
+10 -3
View File
@@ -38,7 +38,9 @@
if (!revList || [revList count] == 0)
return;
//NSDate *start = [NSDate date];
NSThread *currentThread = [NSThread currentThread];
NSDate *lastUpdate = [NSDate date];
NSMutableArray *commits = [NSMutableArray array];
NSInteger counter = 0;
@@ -54,11 +56,16 @@
[searchSHAs addObjectsFromArray:[commit parents]];
}
}
if (++counter % 2000 == 0) {
[self sendCommits:commits];
commits = [NSMutableArray array];
if (++counter % 100 == 0) {
if ([[NSDate date] timeIntervalSinceDate:lastUpdate] > 0.1) {
[self sendCommits:commits];
commits = [NSMutableArray array];
lastUpdate = [NSDate date];
}
}
}
//NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:start];
//NSLog(@"Graphed %i commits in %f seconds (%f/sec)", counter, duration, counter/duration);
[self sendCommits:commits];
[delegate performSelectorOnMainThread:@selector(finishedGraphing) withObject:nil waitUntilDone:NO];
+12 -7
View File
@@ -96,6 +96,7 @@ using namespace std;
- (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
{
NSDate *start = [NSDate date];
NSDate *lastUpdate = [NSDate date];
NSMutableArray *revisions = [NSMutableArray array];
PBGitGrapher *g = [[PBGitGrapher alloc] initWithRepository:repository];
std::map<string, NSStringEncoding> encodingMap;
@@ -125,6 +126,9 @@ using namespace std;
int num = 0;
while (true) {
if ([currentThread isCancelled])
break;
string sha;
if (!getline(stream, sha, '\1'))
break;
@@ -200,18 +204,19 @@ using namespace std;
if (isGraphing)
[g decorateCommit:newCommit];
if (++num % 1000 == 0) {
if ([currentThread isCancelled])
break;
NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys:currentThread, kRevListThreadKey, revisions, kRevListRevisionsKey, nil];
[self performSelectorOnMainThread:@selector(updateCommits:) withObject:update waitUntilDone:NO];
revisions = [NSMutableArray array];
if (++num % 100 == 0) {
if ([[NSDate date] timeIntervalSinceDate:lastUpdate] > 0.1) {
NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys:currentThread, kRevListThreadKey, revisions, kRevListRevisionsKey, nil];
[self performSelectorOnMainThread:@selector(updateCommits:) withObject:update waitUntilDone:NO];
revisions = [NSMutableArray array];
lastUpdate = [NSDate date];
}
}
}
if (![currentThread isCancelled]) {
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:start];
NSLog(@"Loaded %i commits in %f seconds", num, duration);
NSLog(@"Loaded %i commits in %f seconds (%f/sec)", num, duration, num/duration);
// Make sure the commits are stored before exiting.
NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys:currentThread, kRevListThreadKey, revisions, kRevListRevisionsKey, nil];