Mac用艦これ専用ブラウザ おまけ機能付き
Revisão | fc93a13eb69ebbcb68ea9b53d76940f1c2222966 (tree) |
---|---|
Hora | 2015-09-15 22:37:54 |
Autor | masakih <masakih@user...> |
Commiter | masakih |
重複処理を関数にまとめた
@@ -137,6 +137,19 @@ static HMResourceHistoryManager *sInstance; | ||
137 | 137 | |
138 | 138 | } |
139 | 139 | |
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 | + | |
140 | 153 | - (void)reduce:(NSNotification *)notification |
141 | 154 | { |
142 | 155 | dispatch_queue_t queue = dispatch_queue_create("HMResourceHistoryManager", DISPATCH_QUEUE_SERIAL); |
@@ -145,41 +158,21 @@ static HMResourceHistoryManager *sInstance; | ||
145 | 158 | NSLog(@"Start Reduce."); |
146 | 159 | |
147 | 160 | HMResourceHistoryDataStore *resourceStore = [HMResourceHistoryDataStore oneTimeEditor]; |
148 | - NSManagedObjectContext *moc = resourceStore.managedObjectContext; | |
149 | 161 | |
150 | - NSError *error = nil; | |
151 | 162 | // 1 month. |
152 | 163 | NSArray *target = @[@5, @10, @20, @25, @35, @40, @50, @55]; |
153 | 164 | 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); | |
161 | 166 | |
162 | 167 | // 3 month. |
163 | 168 | target = @[@15, @45]; |
164 | 169 | 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); | |
172 | 171 | |
173 | 172 | // 6 month. |
174 | 173 | target = @[@30]; |
175 | 174 | 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); | |
183 | 176 | |
184 | 177 | [resourceStore saveAction:nil]; |
185 | 178 |