Mac用艦これ専用ブラウザ おまけ機能付き
修訂 | 341aa7ab18da150d3b2eb18001bba58f26d450d1 (tree) |
---|---|
時間 | 2015-09-15 00:04:30 |
作者 | masakih <masakih@user...> |
Commiter | masakih |
資源量推移データを間引くようにした
close #35524
@@ -11,6 +11,8 @@ | ||
11 | 11 | #import "HMServerDataStore.h" |
12 | 12 | #import "HMResourceHistoryDataStore.h" |
13 | 13 | |
14 | +#import "HMPeriodicNotifier.h" | |
15 | + | |
14 | 16 | #import "HMKCMaterial.h" |
15 | 17 | #import "HMKCBasic.h" |
16 | 18 | #import "HMKCResource.h" |
@@ -20,6 +22,7 @@ static HMResourceHistoryManager *sInstance; | ||
20 | 22 | |
21 | 23 | @interface HMResourceHistoryManager () |
22 | 24 | @property (strong) NSTimer *timer; |
25 | +@property (strong) HMPeriodicNotifier *periodicNotification; | |
23 | 26 | |
24 | 27 | @end |
25 | 28 | @implementation HMResourceHistoryManager |
@@ -35,6 +38,11 @@ static HMResourceHistoryManager *sInstance; | ||
35 | 38 | |
36 | 39 | - (void)run |
37 | 40 | { |
41 | + self.periodicNotification = [HMPeriodicNotifier periodicNotifierWithHour:23 minutes:3]; | |
42 | + [[NSNotificationCenter defaultCenter] addObserver:self | |
43 | + selector:@selector(reduce:) | |
44 | + name:HMPeriodicNotification | |
45 | + object:self.periodicNotification]; | |
38 | 46 | [self notifyIfNeeded:nil]; |
39 | 47 | |
40 | 48 | } |
@@ -129,4 +137,55 @@ static HMResourceHistoryManager *sInstance; | ||
129 | 137 | |
130 | 138 | } |
131 | 139 | |
140 | +- (void)reduce:(NSNotification *)notification | |
141 | +{ | |
142 | + dispatch_queue_t queue = dispatch_queue_create("HMResourceHistoryManager", DISPATCH_QUEUE_SERIAL); | |
143 | + dispatch_async(queue, ^{ | |
144 | + | |
145 | + NSLog(@"Start Reduce."); | |
146 | + | |
147 | + HMResourceHistoryDataStore *resourceStore = [HMResourceHistoryDataStore oneTimeEditor]; | |
148 | + NSManagedObjectContext *moc = resourceStore.managedObjectContext; | |
149 | + | |
150 | + NSError *error = nil; | |
151 | + // 1 month. | |
152 | + NSArray *target = @[@5, @10, @20, @25, @35, @40, @50, @55]; | |
153 | + NSDate *oneMonthAgo = [NSDate dateWithTimeIntervalSinceNow:-1 * 30 * 24 * 60 * 60]; | |
154 | + NSArray *array = [resourceStore objectsWithEntityName:@"Resource" | |
155 | + error:&error | |
156 | + predicateFormat:@"minute IN %@ AND date < %@", | |
157 | + target, oneMonthAgo]; | |
158 | + for( NSManagedObject *object in array) { | |
159 | + [moc deleteObject:object]; | |
160 | + } | |
161 | + | |
162 | + // 3 month. | |
163 | + target = @[@15, @45]; | |
164 | + NSDate *threeMonthAgo = [NSDate dateWithTimeIntervalSinceNow:-3 * 30 * 24 * 60 * 60]; | |
165 | + array = [resourceStore objectsWithEntityName:@"Resource" | |
166 | + error:&error | |
167 | + predicateFormat:@"minute IN %@ AND date < %@", | |
168 | + target, threeMonthAgo]; | |
169 | + for( NSManagedObject *object in array) { | |
170 | + [moc deleteObject:object]; | |
171 | + } | |
172 | + | |
173 | + // 6 month. | |
174 | + target = @[@30]; | |
175 | + NSDate *sixMonthAgo = [NSDate dateWithTimeIntervalSinceNow:-6 * 30 * 24 * 60 * 60]; | |
176 | + array = [resourceStore objectsWithEntityName:@"Resource" | |
177 | + error:&error | |
178 | + predicateFormat:@"minute IN %@ AND date < %@", | |
179 | + target, sixMonthAgo]; | |
180 | + for( NSManagedObject *object in array) { | |
181 | + [moc deleteObject:object]; | |
182 | + } | |
183 | + | |
184 | + [resourceStore saveAction:nil]; | |
185 | + | |
186 | + NSLog(@"End Reduce."); | |
187 | + }); | |
188 | + | |
189 | +} | |
190 | + | |
132 | 191 | @end |