{"action":"created","comment":{"url":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/comments/71418472","id":71418472,"diff_hunk":"@@ -89,23 +87,31 @@ def insert_postgresql(self, listens):\n                 if not listen.validate():\n                     raise ValueError(\"Invalid listen: %s\" % listen)\n                 try:\n-                    res = connection.execute(\n-                    \"\"\" INSERT INTO listen(user_id, ts, artist_msid, album_msid, recording_msid, raw_data)\n-                        VALUES ( %(user_id)s, to_timestamp(%(ts)s), %(artist_msid)s, %(album_msid)s,\n-                        %(recording_msid)s, %(raw_data)s) ON CONFLICT DO NOTHING \"\"\", self.format_dict(listen))\n+                    params = self.format_dict(listen)\n+                    res = connection.execute(\"\"\"\n+                        INSERT INTO listen(user_id, ts, artist_msid, album_msid, recording_msid)\n+                        VALUES (%(user_id)s, to_timestamp(%(ts)s), %(artist_msid)s, %(album_msid)s,\n+                        %(recording_msid)s) ON CONFLICT DO NOTHING RETURNING id \"\"\", params)\n+                    params['_id'] = res.fetchone()[0]\n+\n+                    res = connection.execute(\"\"\"\n+                        INSERT INTO listen_json(id, data) VALUES (%(_id)s, %(data)s) ON CONFLICT DO NOTHING\n+                    \"\"\", params )\n                 except Exception, e:     # Log errors\n-                        self.log.error(e)\n+                    self.log.error(e)\n \n     def execute(self, query, params={}):\n         with self.engine.connect() as connection:\n             res = connection.execute(query, params)\n             return res.fetchall()\n \n     def fetch_listens_from_storage(self, user_id, from_id, to_id, limit, order, precision):\n-        query = \"\"\" SELECT id, user_id, extract(epoch from ts), artist_msid, album_msid, recording_msid, raw_data \"\"\" + \\\n-                \"\"\" FROM listen WHERE user_id = %(user_id)s \"\"\" + \\\n-                \"\"\" AND extract(epoch from ts) > %(from_id)s AND extract(epoch from ts) < %(to_id)s  \"\"\" + \\\n-                \"\"\" ORDER BY extract(epoch from ts) \"\"\" + ORDER_TEXT[order] + \"\"\" LIMIT %(limit)s\"\"\"\n+        query = \"\"\" SELECT listen.id, user_id, extract(epoch from ts), artist_msid, album_msid, recording_msid, data\n+                    FROM listen, listen_json\n+                    WHERE listen.id = listen_json.id AND user_id = %(user_id)s AND extract(epoch from ts) > %(from_id)s\n+                        AND extract(epoch from ts) < %(to_id)s\n+                    ORDER BY extract(epoch from ts) \"\"\" + ORDER_TEXT[order] + \"\"\" LIMIT %(limit)s\n+                \"\"\"","path":"listenstore/listenstore/listenstore.py","position":null,"original_position":70,"commit_id":"c08e3f88f92929edb605ba1b7539d157c5aab1b0","original_commit_id":"0f834114e5d439113a34e0728e6f92ce76be512e","user":{"login":"pinkeshbadjatiya","id":14854424,"avatar_url":"https://avatars.githubusercontent.com/u/14854424?v=3","gravatar_id":"","url":"https://api.github.com/users/pinkeshbadjatiya","html_url":"https://github.com/pinkeshbadjatiya","followers_url":"https://api.github.com/users/pinkeshbadjatiya/followers","following_url":"https://api.github.com/users/pinkeshbadjatiya/following{/other_user}","gists_url":"https://api.github.com/users/pinkeshbadjatiya/gists{/gist_id}","starred_url":"https://api.github.com/users/pinkeshbadjatiya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pinkeshbadjatiya/subscriptions","organizations_url":"https://api.github.com/users/pinkeshbadjatiya/orgs","repos_url":"https://api.github.com/users/pinkeshbadjatiya/repos","events_url":"https://api.github.com/users/pinkeshbadjatiya/events{/privacy}","received_events_url":"https://api.github.com/users/pinkeshbadjatiya/received_events","type":"User","site_admin":false},"body":"done!","created_at":"2016-07-19T20:38:14Z","updated_at":"2016-07-19T20:38:14Z","html_url":"https://github.com/metabrainz/listenbrainz-server/pull/88#discussion_r71418472","pull_request_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/88","_links":{"self":{"href":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/comments/71418472"},"html":{"href":"https://github.com/metabrainz/listenbrainz-server/pull/88#discussion_r71418472"},"pull_request":{"href":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/88"}}},"pull_request":{"url":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/88","id":77278229,"html_url":"https://github.com/metabrainz/listenbrainz-server/pull/88","diff_url":"https://github.com/metabrainz/listenbrainz-server/pull/88.diff","patch_url":"https://github.com/metabrainz/listenbrainz-server/pull/88.patch","issue_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/issues/88","number":88,"state":"open","locked":false,"title":"Split listen table: listen -> listen + listen_json","user":{"login":"pinkeshbadjatiya","id":14854424,"avatar_url":"https://avatars.githubusercontent.com/u/14854424?v=3","gravatar_id":"","url":"https://api.github.com/users/pinkeshbadjatiya","html_url":"https://github.com/pinkeshbadjatiya","followers_url":"https://api.github.com/users/pinkeshbadjatiya/followers","following_url":"https://api.github.com/users/pinkeshbadjatiya/following{/other_user}","gists_url":"https://api.github.com/users/pinkeshbadjatiya/gists{/gist_id}","starred_url":"https://api.github.com/users/pinkeshbadjatiya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pinkeshbadjatiya/subscriptions","organizations_url":"https://api.github.com/users/pinkeshbadjatiya/orgs","repos_url":"https://api.github.com/users/pinkeshbadjatiya/repos","events_url":"https://api.github.com/users/pinkeshbadjatiya/events{/privacy}","received_events_url":"https://api.github.com/users/pinkeshbadjatiya/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-13T12:15:50Z","updated_at":"2016-07-19T20:38:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2efde82e0cf4e68d4c3445219c074508ac227c0f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/88/commits","review_comments_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/88/comments","review_comment_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/issues/88/comments","statuses_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/statuses/c08e3f88f92929edb605ba1b7539d157c5aab1b0","head":{"label":"pinkeshbadjatiya:change-listens-table","ref":"change-listens-table","sha":"c08e3f88f92929edb605ba1b7539d157c5aab1b0","user":{"login":"pinkeshbadjatiya","id":14854424,"avatar_url":"https://avatars.githubusercontent.com/u/14854424?v=3","gravatar_id":"","url":"https://api.github.com/users/pinkeshbadjatiya","html_url":"https://github.com/pinkeshbadjatiya","followers_url":"https://api.github.com/users/pinkeshbadjatiya/followers","following_url":"https://api.github.com/users/pinkeshbadjatiya/following{/other_user}","gists_url":"https://api.github.com/users/pinkeshbadjatiya/gists{/gist_id}","starred_url":"https://api.github.com/users/pinkeshbadjatiya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pinkeshbadjatiya/subscriptions","organizations_url":"https://api.github.com/users/pinkeshbadjatiya/orgs","repos_url":"https://api.github.com/users/pinkeshbadjatiya/repos","events_url":"https://api.github.com/users/pinkeshbadjatiya/events{/privacy}","received_events_url":"https://api.github.com/users/pinkeshbadjatiya/received_events","type":"User","site_admin":false},"repo":{"id":53163472,"name":"listenbrainz-server","full_name":"pinkeshbadjatiya/listenbrainz-server","owner":{"login":"pinkeshbadjatiya","id":14854424,"avatar_url":"https://avatars.githubusercontent.com/u/14854424?v=3","gravatar_id":"","url":"https://api.github.com/users/pinkeshbadjatiya","html_url":"https://github.com/pinkeshbadjatiya","followers_url":"https://api.github.com/users/pinkeshbadjatiya/followers","following_url":"https://api.github.com/users/pinkeshbadjatiya/following{/other_user}","gists_url":"https://api.github.com/users/pinkeshbadjatiya/gists{/gist_id}","starred_url":"https://api.github.com/users/pinkeshbadjatiya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pinkeshbadjatiya/subscriptions","organizations_url":"https://api.github.com/users/pinkeshbadjatiya/orgs","repos_url":"https://api.github.com/users/pinkeshbadjatiya/repos","events_url":"https://api.github.com/users/pinkeshbadjatiya/events{/privacy}","received_events_url":"https://api.github.com/users/pinkeshbadjatiya/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pinkeshbadjatiya/listenbrainz-server","description":"Server for the ListenBrainz project","fork":true,"url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server","forks_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/forks","keys_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/teams","hooks_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/hooks","issue_events_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/issues/events{/number}","events_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/events","assignees_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/assignees{/user}","branches_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/branches{/branch}","tags_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/tags","blobs_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/statuses/{sha}","languages_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/languages","stargazers_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/stargazers","contributors_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/contributors","subscribers_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/subscribers","subscription_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/subscription","commits_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/contents/{+path}","compare_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/merges","archive_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/downloads","issues_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/issues{/number}","pulls_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/pulls{/number}","milestones_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/milestones{/number}","notifications_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/labels{/name}","releases_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/releases{/id}","deployments_url":"https://api.github.com/repos/pinkeshbadjatiya/listenbrainz-server/deployments","created_at":"2016-03-04T20:28:41Z","updated_at":"2016-03-04T20:28:42Z","pushed_at":"2016-07-19T20:37:10Z","git_url":"git://github.com/pinkeshbadjatiya/listenbrainz-server.git","ssh_url":"git@github.com:pinkeshbadjatiya/listenbrainz-server.git","clone_url":"https://github.com/pinkeshbadjatiya/listenbrainz-server.git","svn_url":"https://github.com/pinkeshbadjatiya/listenbrainz-server","homepage":"https://listenbrainz.org/","size":1279,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"metabrainz:master","ref":"master","sha":"aac58f7df849467afd4566ca2539525d734c3a21","user":{"login":"metabrainz","id":293421,"avatar_url":"https://avatars.githubusercontent.com/u/293421?v=3","gravatar_id":"","url":"https://api.github.com/users/metabrainz","html_url":"https://github.com/metabrainz","followers_url":"https://api.github.com/users/metabrainz/followers","following_url":"https://api.github.com/users/metabrainz/following{/other_user}","gists_url":"https://api.github.com/users/metabrainz/gists{/gist_id}","starred_url":"https://api.github.com/users/metabrainz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metabrainz/subscriptions","organizations_url":"https://api.github.com/users/metabrainz/orgs","repos_url":"https://api.github.com/users/metabrainz/repos","events_url":"https://api.github.com/users/metabrainz/events{/privacy}","received_events_url":"https://api.github.com/users/metabrainz/received_events","type":"Organization","site_admin":false},"repo":{"id":41960013,"name":"listenbrainz-server","full_name":"metabrainz/listenbrainz-server","owner":{"login":"metabrainz","id":293421,"avatar_url":"https://avatars.githubusercontent.com/u/293421?v=3","gravatar_id":"","url":"https://api.github.com/users/metabrainz","html_url":"https://github.com/metabrainz","followers_url":"https://api.github.com/users/metabrainz/followers","following_url":"https://api.github.com/users/metabrainz/following{/other_user}","gists_url":"https://api.github.com/users/metabrainz/gists{/gist_id}","starred_url":"https://api.github.com/users/metabrainz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metabrainz/subscriptions","organizations_url":"https://api.github.com/users/metabrainz/orgs","repos_url":"https://api.github.com/users/metabrainz/repos","events_url":"https://api.github.com/users/metabrainz/events{/privacy}","received_events_url":"https://api.github.com/users/metabrainz/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/metabrainz/listenbrainz-server","description":"Server for the ListenBrainz project","fork":false,"url":"https://api.github.com/repos/metabrainz/listenbrainz-server","forks_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/forks","keys_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/teams","hooks_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/hooks","issue_events_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/issues/events{/number}","events_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/events","assignees_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/assignees{/user}","branches_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/branches{/branch}","tags_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/tags","blobs_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/statuses/{sha}","languages_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/languages","stargazers_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/stargazers","contributors_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/contributors","subscribers_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/subscribers","subscription_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/subscription","commits_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/contents/{+path}","compare_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/merges","archive_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/downloads","issues_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/issues{/number}","pulls_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls{/number}","milestones_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/milestones{/number}","notifications_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/labels{/name}","releases_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/releases{/id}","deployments_url":"https://api.github.com/repos/metabrainz/listenbrainz-server/deployments","created_at":"2015-09-05T12:30:49Z","updated_at":"2016-07-18T18:31:43Z","pushed_at":"2016-07-19T20:37:10Z","git_url":"git://github.com/metabrainz/listenbrainz-server.git","ssh_url":"git@github.com:metabrainz/listenbrainz-server.git","clone_url":"https://github.com/metabrainz/listenbrainz-server.git","svn_url":"https://github.com/metabrainz/listenbrainz-server","homepage":"https://listenbrainz.org/","size":1308,"stargazers_count":62,"watchers_count":62,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":6,"forks":13,"open_issues":6,"watchers":62,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/88"},"html":{"href":"https://github.com/metabrainz/listenbrainz-server/pull/88"},"issue":{"href":"https://api.github.com/repos/metabrainz/listenbrainz-server/issues/88"},"comments":{"href":"https://api.github.com/repos/metabrainz/listenbrainz-server/issues/88/comments"},"review_comments":{"href":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/88/comments"},"review_comment":{"href":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/metabrainz/listenbrainz-server/pulls/88/commits"},"statuses":{"href":"https://api.github.com/repos/metabrainz/listenbrainz-server/statuses/c08e3f88f92929edb605ba1b7539d157c5aab1b0"}}}}
{"actor":{"display_login":"pinkeshbadjatiya"}}