masakih

艦娘は今日も元気です。(公開場所変更)

  • R/O
  • HTTP
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

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


コミットメタ情報

リビジョン341aa7ab18da150d3b2eb18001bba58f26d450d1 (tree)
日時2015-09-15 00:04:30
作者masakih <masakih@user...>
コミッターmasakih

ログメッセージ

資源量推移データを間引くようにした

close #35524

変更サマリ

差分

--- a/KCD/HMResourceHistoryManager.m
+++ b/KCD/HMResourceHistoryManager.m
@@ -11,6 +11,8 @@
1111 #import "HMServerDataStore.h"
1212 #import "HMResourceHistoryDataStore.h"
1313
14+#import "HMPeriodicNotifier.h"
15+
1416 #import "HMKCMaterial.h"
1517 #import "HMKCBasic.h"
1618 #import "HMKCResource.h"
@@ -20,6 +22,7 @@ static HMResourceHistoryManager *sInstance;
2022
2123 @interface HMResourceHistoryManager ()
2224 @property (strong) NSTimer *timer;
25+@property (strong) HMPeriodicNotifier *periodicNotification;
2326
2427 @end
2528 @implementation HMResourceHistoryManager
@@ -35,6 +38,11 @@ static HMResourceHistoryManager *sInstance;
3538
3639 - (void)run
3740 {
41+ self.periodicNotification = [HMPeriodicNotifier periodicNotifierWithHour:23 minutes:3];
42+ [[NSNotificationCenter defaultCenter] addObserver:self
43+ selector:@selector(reduce:)
44+ name:HMPeriodicNotification
45+ object:self.periodicNotification];
3846 [self notifyIfNeeded:nil];
3947
4048 }
@@ -129,4 +137,55 @@ static HMResourceHistoryManager *sInstance;
129137
130138 }
131139
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+
132191 @end