{"action":"created","comment":{"url":"https://api.github.com/repos/matrix-org/synapse/pulls/comments/207540335","pull_request_review_id":143174499,"id":207540335,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwNzU0MDMzNQ==","diff_hunk":"@@ -0,0 +1,119 @@\n+# -*- coding: utf-8 -*-\n+# Copyright 2018 New Vector\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+#     http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+\n+from twisted.internet import defer\n+\n+from synapse.util.caches.descriptors import cached, cachedInlineCallbacks\n+\n+from ._base import SQLBaseStore\n+\n+\n+class MonthlyActiveUsersStore(SQLBaseStore):\n+    def __init__(self, dbconn, hs):\n+        super(MonthlyActiveUsersStore, self).__init__(None, hs)\n+        self._clock = hs.get_clock()\n+        self.hs = hs\n+\n+    def reap_monthly_active_users(self):\n+        \"\"\"\n+        Cleans out monthly active user table to ensure that no stale\n+        entries exist.\n+        Return:\n+            Defered()\n+        \"\"\"\n+        def _reap_users(txn):\n+\n+            thirty_days_ago = (\n+                int(self._clock.time_msec()) - (1000 * 60 * 60 * 24 * 30)\n+            )\n+\n+            sql = \"DELETE FROM monthly_active_users WHERE timestamp < ?\"\n+\n+            txn.execute(sql, (thirty_days_ago,))\n+            sql = \"\"\"\n+                DELETE FROM monthly_active_users\n+                ORDER BY timestamp desc\n+                LIMIT -1 OFFSET ?\n+                \"\"\"\n+            txn.execute(sql, (self.hs.config.max_mau_value,))\n+\n+        res = self.runInteraction(\"reap_monthly_active_users\", _reap_users)\n+        # It seems poor to invalidate the whole cache, Postgres supports\n+        # 'Returning' which would allow me to invalidate only the\n+        # specific users, but sqlite has no way to do this and instead\n+        # I would need to SELECT and the DELETE which without locking\n+        # is racy.\n+        # Have resolved to invalidate the whole cache for now and do\n+        # something about it if and when the perf becomes significant\n+        self.is_user_monthly_active.invalidate_all()\n+        self.get_monthly_active_count.invalidate_all()","path":"synapse/storage/monthly_active_users.py","position":61,"original_position":61,"commit_id":"b2aab04d2c6021e6999fdc3c204db63d7c6f9334","original_commit_id":"b2aab04d2c6021e6999fdc3c204db63d7c6f9334","user":{"login":"erikjohnston","id":8428120,"node_id":"MDQ6VXNlcjg0MjgxMjA=","avatar_url":"https://avatars0.githubusercontent.com/u/8428120?v=4","gravatar_id":"","url":"https://api.github.com/users/erikjohnston","html_url":"https://github.com/erikjohnston","followers_url":"https://api.github.com/users/erikjohnston/followers","following_url":"https://api.github.com/users/erikjohnston/following{/other_user}","gists_url":"https://api.github.com/users/erikjohnston/gists{/gist_id}","starred_url":"https://api.github.com/users/erikjohnston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikjohnston/subscriptions","organizations_url":"https://api.github.com/users/erikjohnston/orgs","repos_url":"https://api.github.com/users/erikjohnston/repos","events_url":"https://api.github.com/users/erikjohnston/events{/privacy}","received_events_url":"https://api.github.com/users/erikjohnston/received_events","type":"User","site_admin":false},"body":"These invalidations should only happen after the transaction has committed, which can be done by yielding on the `self.runInteraction`","created_at":"2018-08-03T13:15:58Z","updated_at":"2018-08-03T13:29:06Z","html_url":"https://github.com/matrix-org/synapse/pull/3633#discussion_r207540335","pull_request_url":"https://api.github.com/repos/matrix-org/synapse/pulls/3633","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/matrix-org/synapse/pulls/comments/207540335"},"html":{"href":"https://github.com/matrix-org/synapse/pull/3633#discussion_r207540335"},"pull_request":{"href":"https://api.github.com/repos/matrix-org/synapse/pulls/3633"}}},"pull_request":{"url":"https://api.github.com/repos/matrix-org/synapse/pulls/3633","id":205155950,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA1MTU1OTUw","html_url":"https://github.com/matrix-org/synapse/pull/3633","diff_url":"https://github.com/matrix-org/synapse/pull/3633.diff","patch_url":"https://github.com/matrix-org/synapse/pull/3633.patch","issue_url":"https://api.github.com/repos/matrix-org/synapse/issues/3633","number":3633,"state":"open","locked":false,"title":"API for monthly_active_users table","user":{"login":"neilisfragile","id":451032,"node_id":"MDQ6VXNlcjQ1MTAzMg==","avatar_url":"https://avatars2.githubusercontent.com/u/451032?v=4","gravatar_id":"","url":"https://api.github.com/users/neilisfragile","html_url":"https://github.com/neilisfragile","followers_url":"https://api.github.com/users/neilisfragile/followers","following_url":"https://api.github.com/users/neilisfragile/following{/other_user}","gists_url":"https://api.github.com/users/neilisfragile/gists{/gist_id}","starred_url":"https://api.github.com/users/neilisfragile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neilisfragile/subscriptions","organizations_url":"https://api.github.com/users/neilisfragile/orgs","repos_url":"https://api.github.com/users/neilisfragile/repos","events_url":"https://api.github.com/users/neilisfragile/events{/privacy}","received_events_url":"https://api.github.com/users/neilisfragile/received_events","type":"User","site_admin":false},"body":"Doesn't actually do anything other than ensure that table purges old values.\r\n\r\nWill form basis for extending #3630 ","created_at":"2018-07-31T15:38:37Z","updated_at":"2018-08-03T13:29:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de981db3055ddcd19e6bf814139eba4397747c7a","assignee":{"login":"neilisfragile","id":451032,"node_id":"MDQ6VXNlcjQ1MTAzMg==","avatar_url":"https://avatars2.githubusercontent.com/u/451032?v=4","gravatar_id":"","url":"https://api.github.com/users/neilisfragile","html_url":"https://github.com/neilisfragile","followers_url":"https://api.github.com/users/neilisfragile/followers","following_url":"https://api.github.com/users/neilisfragile/following{/other_user}","gists_url":"https://api.github.com/users/neilisfragile/gists{/gist_id}","starred_url":"https://api.github.com/users/neilisfragile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neilisfragile/subscriptions","organizations_url":"https://api.github.com/users/neilisfragile/orgs","repos_url":"https://api.github.com/users/neilisfragile/repos","events_url":"https://api.github.com/users/neilisfragile/events{/privacy}","received_events_url":"https://api.github.com/users/neilisfragile/received_events","type":"User","site_admin":false},"assignees":[{"login":"neilisfragile","id":451032,"node_id":"MDQ6VXNlcjQ1MTAzMg==","avatar_url":"https://avatars2.githubusercontent.com/u/451032?v=4","gravatar_id":"","url":"https://api.github.com/users/neilisfragile","html_url":"https://github.com/neilisfragile","followers_url":"https://api.github.com/users/neilisfragile/followers","following_url":"https://api.github.com/users/neilisfragile/following{/other_user}","gists_url":"https://api.github.com/users/neilisfragile/gists{/gist_id}","starred_url":"https://api.github.com/users/neilisfragile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neilisfragile/subscriptions","organizations_url":"https://api.github.com/users/neilisfragile/orgs","repos_url":"https://api.github.com/users/neilisfragile/repos","events_url":"https://api.github.com/users/neilisfragile/events{/privacy}","received_events_url":"https://api.github.com/users/neilisfragile/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/matrix-org/synapse/pulls/3633/commits","review_comments_url":"https://api.github.com/repos/matrix-org/synapse/pulls/3633/comments","review_comment_url":"https://api.github.com/repos/matrix-org/synapse/pulls/comments{/number}","comments_url":"https://api.github.com/repos/matrix-org/synapse/issues/3633/comments","statuses_url":"https://api.github.com/repos/matrix-org/synapse/statuses/b2aab04d2c6021e6999fdc3c204db63d7c6f9334","head":{"label":"matrix-org:neilj/mau_tracker","ref":"neilj/mau_tracker","sha":"b2aab04d2c6021e6999fdc3c204db63d7c6f9334","user":{"login":"matrix-org","id":8418310,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0MTgzMTA=","avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":22844864,"node_id":"MDEwOlJlcG9zaXRvcnkyMjg0NDg2NA==","name":"synapse","full_name":"matrix-org/synapse","owner":{"login":"matrix-org","id":8418310,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0MTgzMTA=","avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/synapse","description":"Synapse: Matrix reference homeserver","fork":false,"url":"https://api.github.com/repos/matrix-org/synapse","forks_url":"https://api.github.com/repos/matrix-org/synapse/forks","keys_url":"https://api.github.com/repos/matrix-org/synapse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/synapse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/synapse/teams","hooks_url":"https://api.github.com/repos/matrix-org/synapse/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/synapse/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/synapse/events","assignees_url":"https://api.github.com/repos/matrix-org/synapse/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/synapse/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/synapse/tags","blobs_url":"https://api.github.com/repos/matrix-org/synapse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/synapse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/synapse/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/synapse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/synapse/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/synapse/languages","stargazers_url":"https://api.github.com/repos/matrix-org/synapse/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/synapse/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/synapse/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/synapse/subscription","commits_url":"https://api.github.com/repos/matrix-org/synapse/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/synapse/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/synapse/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/synapse/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/synapse/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/synapse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/synapse/merges","archive_url":"https://api.github.com/repos/matrix-org/synapse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/synapse/downloads","issues_url":"https://api.github.com/repos/matrix-org/synapse/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/synapse/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/synapse/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/synapse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/synapse/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/synapse/releases{/id}","deployments_url":"https://api.github.com/repos/matrix-org/synapse/deployments","created_at":"2014-08-11T15:51:42Z","updated_at":"2018-08-03T02:53:32Z","pushed_at":"2018-08-03T13:13:09Z","git_url":"git://github.com/matrix-org/synapse.git","ssh_url":"git@github.com:matrix-org/synapse.git","clone_url":"https://github.com/matrix-org/synapse.git","svn_url":"https://github.com/matrix-org/synapse","homepage":"http://matrix.org","size":21218,"stargazers_count":3131,"watchers_count":3131,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":443,"mirror_url":null,"archived":false,"open_issues_count":944,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":443,"open_issues":944,"watchers":3131,"default_branch":"master"}},"base":{"label":"matrix-org:develop","ref":"develop","sha":"8a86d7ea962c984aef373b628713692e92619c79","user":{"login":"matrix-org","id":8418310,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0MTgzMTA=","avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":22844864,"node_id":"MDEwOlJlcG9zaXRvcnkyMjg0NDg2NA==","name":"synapse","full_name":"matrix-org/synapse","owner":{"login":"matrix-org","id":8418310,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0MTgzMTA=","avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/synapse","description":"Synapse: Matrix reference homeserver","fork":false,"url":"https://api.github.com/repos/matrix-org/synapse","forks_url":"https://api.github.com/repos/matrix-org/synapse/forks","keys_url":"https://api.github.com/repos/matrix-org/synapse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/synapse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/synapse/teams","hooks_url":"https://api.github.com/repos/matrix-org/synapse/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/synapse/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/synapse/events","assignees_url":"https://api.github.com/repos/matrix-org/synapse/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/synapse/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/synapse/tags","blobs_url":"https://api.github.com/repos/matrix-org/synapse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/synapse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/synapse/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/synapse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/synapse/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/synapse/languages","stargazers_url":"https://api.github.com/repos/matrix-org/synapse/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/synapse/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/synapse/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/synapse/subscription","commits_url":"https://api.github.com/repos/matrix-org/synapse/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/synapse/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/synapse/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/synapse/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/synapse/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/synapse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/synapse/merges","archive_url":"https://api.github.com/repos/matrix-org/synapse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/synapse/downloads","issues_url":"https://api.github.com/repos/matrix-org/synapse/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/synapse/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/synapse/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/synapse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/synapse/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/synapse/releases{/id}","deployments_url":"https://api.github.com/repos/matrix-org/synapse/deployments","created_at":"2014-08-11T15:51:42Z","updated_at":"2018-08-03T02:53:32Z","pushed_at":"2018-08-03T13:13:09Z","git_url":"git://github.com/matrix-org/synapse.git","ssh_url":"git@github.com:matrix-org/synapse.git","clone_url":"https://github.com/matrix-org/synapse.git","svn_url":"https://github.com/matrix-org/synapse","homepage":"http://matrix.org","size":21218,"stargazers_count":3131,"watchers_count":3131,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":443,"mirror_url":null,"archived":false,"open_issues_count":944,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":443,"open_issues":944,"watchers":3131,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/matrix-org/synapse/pulls/3633"},"html":{"href":"https://github.com/matrix-org/synapse/pull/3633"},"issue":{"href":"https://api.github.com/repos/matrix-org/synapse/issues/3633"},"comments":{"href":"https://api.github.com/repos/matrix-org/synapse/issues/3633/comments"},"review_comments":{"href":"https://api.github.com/repos/matrix-org/synapse/pulls/3633/comments"},"review_comment":{"href":"https://api.github.com/repos/matrix-org/synapse/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/matrix-org/synapse/pulls/3633/commits"},"statuses":{"href":"https://api.github.com/repos/matrix-org/synapse/statuses/b2aab04d2c6021e6999fdc3c204db63d7c6f9334"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"erikjohnston"}}