Added a hack to de-duplicate hosts and some more checks when adding a host to minimize the chances for dupes
This commit is contained in:
1 parent
40a04eb08b
commit
fd9ee45dac
4 files changed
+98
-10
No files matched your search
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// CleanupCrew.m
|
||||
// Limelight
|
||||
//
|
||||
// Created by Diego Waxemberg on 4/5/15.
|
||||
// Copyright (c) 2015 Limelight Stream. All rights reserved.
|
||||
//
|
||||
|
||||
#import "CleanupCrew.h"
|
||||
|
||||
@implementation CleanupCrew {
|
||||
NSArray* _hostList;
|
||||
id<CleanupCallback> _callback;
|
||||
}
|
||||
|
||||
static const int CLEANUP_RATE = 2;
|
||||
|
||||
|
||||
- (id) initWithHostList:(NSArray *)hostList andCallback:(id<CleanupCallback>)callback {
|
||||
self = [super init];
|
||||
_hostList = hostList;
|
||||
_callback = callback;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) main {
|
||||
while (!self.isCancelled) {
|
||||
NSMutableSet* dirtyHosts = [[NSMutableSet alloc] init];
|
||||
|
||||
for (Host* host in _hostList) {
|
||||
for (Host* other in _hostList) {
|
||||
if (self.isCancelled) {
|
||||
break;
|
||||
}
|
||||
|
||||
// We check the name as well as a hack to remove duplicates
|
||||
if (host != other && ([host.uuid isEqualToString:other.uuid]
|
||||
|| [host.name isEqualToString:other.name])) {
|
||||
[dirtyHosts addObject:other];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dirtyHosts.count > 0) {
|
||||
[_callback cleanedUpHosts:dirtyHosts];
|
||||
}
|
||||
|
||||
if (!self.cancelled) {
|
||||
[NSThread sleepForTimeInterval:CLEANUP_RATE];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user