• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonbathyscaphephpgamewindowsguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

Mac用艦これ専用ブラウザ おまけ機能付き


Commit MetaInfo

Révisionfc93a13eb69ebbcb68ea9b53d76940f1c2222966 (tree)
l'heure2015-09-15 22:37:54
Auteurmasakih <masakih@user...>
Commitermasakih

Message de Log

重複処理を関数にまとめた

Change Summary

Modification

--- a/KCD/HMResourceHistoryManager.m
+++ b/KCD/HMResourceHistoryManager.m
@@ -137,6 +137,19 @@ static HMResourceHistoryManager *sInstance;
137137
138138 }
139139
140+void reduceResourceByConditions(HMResourceHistoryDataStore *resourceStore, NSArray *target, NSDate *oneMonthAgo)
141+{
142+ NSError *error = nil;
143+ NSManagedObjectContext *moc = resourceStore.managedObjectContext;
144+ NSArray *array = [resourceStore objectsWithEntityName:@"Resource"
145+ error:&error
146+ predicateFormat:@"minute IN %@ AND date < %@",
147+ target, oneMonthAgo];
148+ for( NSManagedObject *object in array) {
149+ [moc deleteObject:object];
150+ }
151+}
152+
140153 - (void)reduce:(NSNotification *)notification
141154 {
142155 dispatch_queue_t queue = dispatch_queue_create("HMResourceHistoryManager", DISPATCH_QUEUE_SERIAL);
@@ -145,41 +158,21 @@ static HMResourceHistoryManager *sInstance;
145158 NSLog(@"Start Reduce.");
146159
147160 HMResourceHistoryDataStore *resourceStore = [HMResourceHistoryDataStore oneTimeEditor];
148- NSManagedObjectContext *moc = resourceStore.managedObjectContext;
149161
150- NSError *error = nil;
151162 // 1 month.
152163 NSArray *target = @[@5, @10, @20, @25, @35, @40, @50, @55];
153164 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- }
165+ reduceResourceByConditions(resourceStore, target, oneMonthAgo);
161166
162167 // 3 month.
163168 target = @[@15, @45];
164169 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- }
170+ reduceResourceByConditions(resourceStore, target, threeMonthAgo);
172171
173172 // 6 month.
174173 target = @[@30];
175174 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- }
175+ reduceResourceByConditions(resourceStore, target, sixMonthAgo);
183176
184177 [resourceStore saveAction:nil];
185178