{"action":"created","comment":{"url":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/comments/85349264","pull_request_review_id":6070536,"id":85349264,"diff_hunk":"@@ -21,80 +22,98 @@ - (void)performHouseKeepingWithCompletion:(dispatch_block_t)completion{\n                         }];\n         [transaction removeObjectsForKeys:keysToRemove inCollection:[MWKHistoryEntry databaseCollectionName]];\n     }];\n-    \n+\n+    //Remove all content groups older than 30 days\n     [connection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {\n-        \n-        NSMutableArray* keysToRemove = [NSMutableArray array];\n-        \n+\n+        NSDate *thirtyDays = [[NSDate date] dateBySubtractingDays:30];\n+\n+        NSMutableArray *keysToRemove = [NSMutableArray array];\n+\n+        [transaction enumerateKeysAndObjectsInCollection:[WMFContentGroup databaseCollectionName]\n+                                              usingBlock:^(NSString *_Nonnull key, WMFContentGroup *_Nonnull object, BOOL *_Nonnull stop) {\n+\n+                                                  if ([object.date isEarlierThanDate:thirtyDays]) {\n+                                                      [keysToRemove addObject:key];\n+                                                  }\n+                                              }];\n+\n+        [transaction removeObjectsForKeys:keysToRemove inCollection:[WMFContentGroup databaseCollectionName]];\n+    }];\n+\n+    //Remove previews that are uneeded\n+    [connection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {\n+\n+        NSMutableArray *keysToRemove = [NSMutableArray array];\n+\n         //add keys for all previews\n-        [transaction enumerateKeysInCollection:[WMFArticlePreview databaseCollectionName] usingBlock:^(NSString * _Nonnull key, BOOL * _Nonnull stop) {\n-            [keysToRemove addObject:key];\n-        }];\n-        \n+        [transaction enumerateKeysInCollection:[WMFArticlePreview databaseCollectionName]\n+                                    usingBlock:^(NSString *_Nonnull key, BOOL *_Nonnull stop) {\n+                                        [keysToRemove addObject:key];\n+                                    }];\n+\n         //remove anything with a matching key in history\n-        [transaction enumerateKeysInCollection:[MWKHistoryEntry databaseCollectionName] usingBlock:^(NSString * _Nonnull key, BOOL * _Nonnull stop) {\n-            [keysToRemove removeObject:key];\n-        }];\n-        \n+        [transaction enumerateKeysInCollection:[MWKHistoryEntry databaseCollectionName]\n+                                    usingBlock:^(NSString *_Nonnull key, BOOL *_Nonnull stop) {\n+                                        [keysToRemove removeObject:key];\n+                                    }];\n+\n         //remove anything not in the content group store\n-        [transaction enumerateRowsInCollection:[WMFContentGroup databaseCollectionName] usingBlock:^(NSString * _Nonnull key, WMFContentGroup*  _Nonnull object, NSArray*  _Nullable metadata, BOOL * _Nonnull stop) {\n-            \n-            //keep any sources of related pages\n-            if([object isKindOfClass:[WMFRelatedPagesContentGroup class]]){\n-                [keysToRemove removeObject:[((WMFRelatedPagesContentGroup*)object).articleURL absoluteString]];\n-            }\n-            \n-            if(![metadata isKindOfClass:[NSArray class]]){\n-                NSAssert(NO, @\"Unknown Content Type\");\n-                return;\n-            }\n-            \n-            //keep previews for any linked content\n-            switch (object.contentType) {\n-                case WMFContentTypeURL: {\n-                    [metadata enumerateObjectsUsingBlock:^(NSURL*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {\n-                        [keysToRemove removeObject:[obj absoluteString]];\n-                    }];\n-                }\n-                    break;\n-                case WMFContentTypeTopReadPreview: {\n-                    [metadata enumerateObjectsUsingBlock:^(WMFFeedTopReadArticlePreview*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {\n-                        [keysToRemove removeObject:[obj.articleURL absoluteString]];\n-                    }];\n-                    \n-                }\n-                    break;\n-                case WMFContentTypeStory: {\n-                    [metadata enumerateObjectsUsingBlock:^(WMFFeedNewsStory*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {\n-                        [obj.articlePreviews enumerateObjectsUsingBlock:^(WMFFeedArticlePreview * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {\n-                            [keysToRemove removeObject:[obj.articleURL absoluteString]];\n-                        }];\n-                    }];\n-                }\n-                    break;\n-                case WMFContentTypeImage: {\n-                    //Nothing to do\n-                }\n-                    break;\n-                    \n-                default:\n-                    NSAssert(NO, @\"Unknown Content Type\");\n-                    break;\n-            }\n-            \n-            \n-        }];\n-        \n+        [transaction enumerateRowsInCollection:[WMFContentGroup databaseCollectionName]\n+                                    usingBlock:^(NSString *_Nonnull key, WMFContentGroup *_Nonnull object, NSArray *_Nullable metadata, BOOL *_Nonnull stop) {\n+\n+                                        //keep any sources of related pages\n+                                        if ([object isKindOfClass:[WMFRelatedPagesContentGroup class]]) {\n+                                            [keysToRemove removeObject:[((WMFRelatedPagesContentGroup *)object).articleURL absoluteString]];\n+                                        }\n+\n+                                        if (![metadata isKindOfClass:[NSArray class]]) {\n+                                            NSAssert(NO, @\"Unknown Content Type\");\n+                                            return;\n+                                        }\n+\n+                                        //keep previews for any linked content\n+                                        switch (object.contentType) {\n+                                            case WMFContentTypeURL: {\n+                                                [metadata enumerateObjectsUsingBlock:^(NSURL *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {\n+                                                    [keysToRemove removeObject:[obj absoluteString]];","path":"Wikipedia/Code/WMFDatabaseHouseKeeper.m","position":79,"original_position":138,"commit_id":"348fa71b8089ecff1327c77cf838fb62599b2447","original_commit_id":"bde595196b79dccd46d4a05ee97b2b449e8b39f5","user":{"login":"joewalsh","id":741327,"avatar_url":"https://avatars.githubusercontent.com/u/741327?v=3","gravatar_id":"","url":"https://api.github.com/users/joewalsh","html_url":"https://github.com/joewalsh","followers_url":"https://api.github.com/users/joewalsh/followers","following_url":"https://api.github.com/users/joewalsh/following{/other_user}","gists_url":"https://api.github.com/users/joewalsh/gists{/gist_id}","starred_url":"https://api.github.com/users/joewalsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joewalsh/subscriptions","organizations_url":"https://api.github.com/users/joewalsh/orgs","repos_url":"https://api.github.com/users/joewalsh/repos","events_url":"https://api.github.com/users/joewalsh/events{/privacy}","received_events_url":"https://api.github.com/users/joewalsh/received_events","type":"User","site_admin":false},"body":"one more","created_at":"2016-10-27T14:31:52Z","updated_at":"2016-10-27T14:32:07Z","html_url":"https://github.com/wikimedia/wikipedia-ios/pull/986#discussion_r85349264","pull_request_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/986","_links":{"self":{"href":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/comments/85349264"},"html":{"href":"https://github.com/wikimedia/wikipedia-ios/pull/986#discussion_r85349264"},"pull_request":{"href":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/986"}}},"pull_request":{"url":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/986","id":91074856,"html_url":"https://github.com/wikimedia/wikipedia-ios/pull/986","diff_url":"https://github.com/wikimedia/wikipedia-ios/pull/986.diff","patch_url":"https://github.com/wikimedia/wikipedia-ios/pull/986.patch","issue_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues/986","number":986,"state":"open","locked":false,"title":"Feature/cleanup","user":{"login":"coreyfloyd","id":64771,"avatar_url":"https://avatars.githubusercontent.com/u/64771?v=3","gravatar_id":"","url":"https://api.github.com/users/coreyfloyd","html_url":"https://github.com/coreyfloyd","followers_url":"https://api.github.com/users/coreyfloyd/followers","following_url":"https://api.github.com/users/coreyfloyd/following{/other_user}","gists_url":"https://api.github.com/users/coreyfloyd/gists{/gist_id}","starred_url":"https://api.github.com/users/coreyfloyd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreyfloyd/subscriptions","organizations_url":"https://api.github.com/users/coreyfloyd/orgs","repos_url":"https://api.github.com/users/coreyfloyd/repos","events_url":"https://api.github.com/users/coreyfloyd/events{/privacy}","received_events_url":"https://api.github.com/users/coreyfloyd/received_events","type":"User","site_admin":false},"body":"https://phabricator.wikimedia.org/T148192\r\nhttps://phabricator.wikimedia.org/T148194\r\n\r\nCleaning up various items in the database\r\n\r\nRefactored to a cleanup class and only do on backgrounding to ensure its only running once since we may have multiple data stores\r\n\r\n\r\n","created_at":"2016-10-26T19:48:28Z","updated_at":"2016-10-27T14:32:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"57e597ce03746f15f9896b18cee3db636da0243f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/986/commits","review_comments_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/986/comments","review_comment_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues/986/comments","statuses_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/statuses/348fa71b8089ecff1327c77cf838fb62599b2447","head":{"label":"wikimedia:feature/cleanup","ref":"feature/cleanup","sha":"348fa71b8089ecff1327c77cf838fb62599b2447","user":{"login":"wikimedia","id":56668,"avatar_url":"https://avatars.githubusercontent.com/u/56668?v=3","gravatar_id":"","url":"https://api.github.com/users/wikimedia","html_url":"https://github.com/wikimedia","followers_url":"https://api.github.com/users/wikimedia/followers","following_url":"https://api.github.com/users/wikimedia/following{/other_user}","gists_url":"https://api.github.com/users/wikimedia/gists{/gist_id}","starred_url":"https://api.github.com/users/wikimedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wikimedia/subscriptions","organizations_url":"https://api.github.com/users/wikimedia/orgs","repos_url":"https://api.github.com/users/wikimedia/repos","events_url":"https://api.github.com/users/wikimedia/events{/privacy}","received_events_url":"https://api.github.com/users/wikimedia/received_events","type":"Organization","site_admin":false},"repo":{"id":13863130,"name":"wikipedia-ios","full_name":"wikimedia/wikipedia-ios","owner":{"login":"wikimedia","id":56668,"avatar_url":"https://avatars.githubusercontent.com/u/56668?v=3","gravatar_id":"","url":"https://api.github.com/users/wikimedia","html_url":"https://github.com/wikimedia","followers_url":"https://api.github.com/users/wikimedia/followers","following_url":"https://api.github.com/users/wikimedia/following{/other_user}","gists_url":"https://api.github.com/users/wikimedia/gists{/gist_id}","starred_url":"https://api.github.com/users/wikimedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wikimedia/subscriptions","organizations_url":"https://api.github.com/users/wikimedia/orgs","repos_url":"https://api.github.com/users/wikimedia/repos","events_url":"https://api.github.com/users/wikimedia/events{/privacy}","received_events_url":"https://api.github.com/users/wikimedia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wikimedia/wikipedia-ios","description":"The official Wikipedia iOS app.","fork":false,"url":"https://api.github.com/repos/wikimedia/wikipedia-ios","forks_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/forks","keys_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/teams","hooks_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/hooks","issue_events_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues/events{/number}","events_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/events","assignees_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/assignees{/user}","branches_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/branches{/branch}","tags_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/tags","blobs_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/refs{/sha}","trees_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/statuses/{sha}","languages_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/languages","stargazers_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/stargazers","contributors_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/contributors","subscribers_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/subscribers","subscription_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/subscription","commits_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/commits{/sha}","git_commits_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/commits{/sha}","comments_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/comments{/number}","issue_comment_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues/comments{/number}","contents_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/contents/{+path}","compare_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/merges","archive_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/downloads","issues_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues{/number}","pulls_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls{/number}","milestones_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/milestones{/number}","notifications_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/labels{/name}","releases_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/releases{/id}","deployments_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/deployments","created_at":"2013-10-25T14:36:56Z","updated_at":"2016-10-27T03:45:02Z","pushed_at":"2016-10-27T14:26:21Z","git_url":"git://github.com/wikimedia/wikipedia-ios.git","ssh_url":"git@github.com:wikimedia/wikipedia-ios.git","clone_url":"https://github.com/wikimedia/wikipedia-ios.git","svn_url":"https://github.com/wikimedia/wikipedia-ios","homepage":"https://www.mediawiki.org/wiki/Wikimedia_Apps","size":274483,"stargazers_count":905,"watchers_count":905,"language":"Objective-C","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":275,"mirror_url":null,"open_issues_count":6,"forks":275,"open_issues":6,"watchers":905,"default_branch":"develop"}},"base":{"label":"wikimedia:develop","ref":"develop","sha":"5c5d21f1d8769b81464a9ac02768d264e0939d78","user":{"login":"wikimedia","id":56668,"avatar_url":"https://avatars.githubusercontent.com/u/56668?v=3","gravatar_id":"","url":"https://api.github.com/users/wikimedia","html_url":"https://github.com/wikimedia","followers_url":"https://api.github.com/users/wikimedia/followers","following_url":"https://api.github.com/users/wikimedia/following{/other_user}","gists_url":"https://api.github.com/users/wikimedia/gists{/gist_id}","starred_url":"https://api.github.com/users/wikimedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wikimedia/subscriptions","organizations_url":"https://api.github.com/users/wikimedia/orgs","repos_url":"https://api.github.com/users/wikimedia/repos","events_url":"https://api.github.com/users/wikimedia/events{/privacy}","received_events_url":"https://api.github.com/users/wikimedia/received_events","type":"Organization","site_admin":false},"repo":{"id":13863130,"name":"wikipedia-ios","full_name":"wikimedia/wikipedia-ios","owner":{"login":"wikimedia","id":56668,"avatar_url":"https://avatars.githubusercontent.com/u/56668?v=3","gravatar_id":"","url":"https://api.github.com/users/wikimedia","html_url":"https://github.com/wikimedia","followers_url":"https://api.github.com/users/wikimedia/followers","following_url":"https://api.github.com/users/wikimedia/following{/other_user}","gists_url":"https://api.github.com/users/wikimedia/gists{/gist_id}","starred_url":"https://api.github.com/users/wikimedia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wikimedia/subscriptions","organizations_url":"https://api.github.com/users/wikimedia/orgs","repos_url":"https://api.github.com/users/wikimedia/repos","events_url":"https://api.github.com/users/wikimedia/events{/privacy}","received_events_url":"https://api.github.com/users/wikimedia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wikimedia/wikipedia-ios","description":"The official Wikipedia iOS app.","fork":false,"url":"https://api.github.com/repos/wikimedia/wikipedia-ios","forks_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/forks","keys_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/teams","hooks_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/hooks","issue_events_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues/events{/number}","events_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/events","assignees_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/assignees{/user}","branches_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/branches{/branch}","tags_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/tags","blobs_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/refs{/sha}","trees_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/statuses/{sha}","languages_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/languages","stargazers_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/stargazers","contributors_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/contributors","subscribers_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/subscribers","subscription_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/subscription","commits_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/commits{/sha}","git_commits_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/git/commits{/sha}","comments_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/comments{/number}","issue_comment_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues/comments{/number}","contents_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/contents/{+path}","compare_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/merges","archive_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/downloads","issues_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues{/number}","pulls_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls{/number}","milestones_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/milestones{/number}","notifications_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/labels{/name}","releases_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/releases{/id}","deployments_url":"https://api.github.com/repos/wikimedia/wikipedia-ios/deployments","created_at":"2013-10-25T14:36:56Z","updated_at":"2016-10-27T03:45:02Z","pushed_at":"2016-10-27T14:26:21Z","git_url":"git://github.com/wikimedia/wikipedia-ios.git","ssh_url":"git@github.com:wikimedia/wikipedia-ios.git","clone_url":"https://github.com/wikimedia/wikipedia-ios.git","svn_url":"https://github.com/wikimedia/wikipedia-ios","homepage":"https://www.mediawiki.org/wiki/Wikimedia_Apps","size":274483,"stargazers_count":905,"watchers_count":905,"language":"Objective-C","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":275,"mirror_url":null,"open_issues_count":6,"forks":275,"open_issues":6,"watchers":905,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/986"},"html":{"href":"https://github.com/wikimedia/wikipedia-ios/pull/986"},"issue":{"href":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues/986"},"comments":{"href":"https://api.github.com/repos/wikimedia/wikipedia-ios/issues/986/comments"},"review_comments":{"href":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/986/comments"},"review_comment":{"href":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wikimedia/wikipedia-ios/pulls/986/commits"},"statuses":{"href":"https://api.github.com/repos/wikimedia/wikipedia-ios/statuses/348fa71b8089ecff1327c77cf838fb62599b2447"}}}}
{"actor":{"display_login":"joewalsh"}}