GitHub PullRequestReviewCommentEvent at 2014-07-21 23:42:27
Repository: zamboni
Actor: robhudson
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/zamboni/pulls/comments/15203923","id":15203923,"diff_hunk":"@@ -357,16 +361,172 @@ class FeedView(CORSMixin, APIView):\n     permission_classes = []\n     cors_allowed_methods = ('get',)\n \n+    def get_es_feed_query(self, region=None, carrier=None):\n+        \"\"\"\n+        Build ES query for feed.\n+        Weights on region and carrier if passed in.\n+        Operator shelf on top if region and carrier passed in.\n+\n+        region -- region ID (integer)\n+        carrier -- carrier ID (integer)\n+        \"\"\"\n+        query = {\n+            'function_score': {\n+                'functions': []\n+            }\n+        }\n+\n+        if region:\n+            # Filter by region.\n+            query['function_score']['filter'] = {\n+                'bool': {\n+                    'must': [\n+                        {'term': {'region': region}}\n+                    ],\n+                    'must_not': []\n+                }\n+            }\n+\n+        if region and carrier:\n+            # Boost shelf to top.\n+            query['function_score']['functions'].append({\n+                'boost_factor': 10000.0,\n+                'filter': {\n+                    'term': {'item_type': feed.FEED_TYPE_SHELF},\n+                }\n+            })\n+\n+            # Exclude shelves that do not match region + carrier.\n+            query['function_score']['filter']['bool']['must_not'].append({\n+                'and': [\n+                    {'term': {'item_type': feed.FEED_TYPE_SHELF}},\n+                    {'not': {'term': {'carrier': carrier}}}\n+                ]\n+            })\n+\n+        return {\n+            'query': query\n+        }\n+\n+    def get_es_feed_element_query(self, feed_items):\n+        \"\"\"\n+        From a list of FeedItems with normalized feed element IDs,\n+        return an ES query that fetches the feed elements for each feed item.\n+        \"\"\"\n+        or_filters = []\n+        for feed_item in feed_items:\n+            or_filters.append({\n+                'term': {\n+                    'id': feed_item[feed_item['item_type']],\n+                    'item_type': feed_item['item_type']\n+                }\n+            })\n+\n+        return {\n+            'query': {\n+                'filtered': {\n+                    'query': {\n+                        'match_all': {},\n+                    },\n+                    'filter': {\n+                        'or': or_filters\n+                    }\n+                }\n+            }\n+        }\n+\n+    def get_es_apps_query(self, apps):\n+        \"\"\"\n+        From a list of app IDs, fetch apps from ES.\n+        \"\"\"\n+        or_filters = []\n+        for app in apps:\n+            or_filters.append({\n+                'term': {\n+                    'id': app,\n+                }\n+            })\n+\n+        return {\n+            'query': {\n+                'filtered': {\n+                    'query': {\n+                        'match_all': {},\n+                    },\n+                    'filter': {\n+                        'bool': {\n+                            'should': or_filters\n+                        }\n+                    }\n+                }\n+            }\n+        }\n+\n     def get(self, request, *args, **kwargs):\n-        filterer = RegionCarrierFilter()\n-        data = {\n-            'feed': [],\n-            'shelf': None\n+        indexer = FeedItem.get_indexer()\n+        es = indexer.get_es(urls=settings.ES_URLS)\n+\n+        # Parse carrier and region.\n+        q = request.QUERY_PARAMS\n+        region = None\n+        carrier = None\n+        if q.get('region'):\n+            region = mkt.regions.REGIONS_DICT[q['region']].id\n+        if q.get('carrier'):\n+            carrier = mkt.carriers.CARRIER_MAP[q['carrier']].id","path":"mkt/feed/views.py","position":144,"original_position":144,"commit_id":"6ebbcb80ebc244dc4a61522756a10e599a172481","original_commit_id":"6ebbcb80ebc244dc4a61522756a10e599a172481","user":{"login":"robhudson","id":1106,"avatar_url":"https://avatars.githubusercontent.com/u/1106?","gravatar_id":"47ae07204a8b5c27fcfa9d6d253bba4e","url":"https://api.github.com/users/robhudson","html_url":"https://github.com/robhudson","followers_url":"https://api.github.com/users/robhudson/followers","following_url":"https://api.github.com/users/robhudson/following{/other_user}","gists_url":"https://api.github.com/users/robhudson/gists{/gist_id}","starred_url":"https://api.github.com/users/robhudson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robhudson/subscriptions","organizations_url":"https://api.github.com/users/robhudson/orgs","repos_url":"https://api.github.com/users/robhudson/repos","events_url":"https://api.github.com/users/robhudson/events{/privacy}","received_events_url":"https://api.github.com/users/robhudson/received_events","type":"User","site_admin":false},"body":"This isn't already done in middleware?","created_at":"2014-07-21T23:42:27Z","updated_at":"2014-07-21T23:42:27Z","html_url":"https://github.com/mozilla/zamboni/pull/2315#discussion_r15203923","pull_request_url":"https://api.github.com/repos/mozilla/zamboni/pulls/2315","_links":{"self":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/comments/15203923"},"html":{"href":"https://github.com/mozilla/zamboni/pull/2315#discussion_r15203923"},"pull_request":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/2315"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/zamboni/pulls/2315","id":18363959,"html_url":"https://github.com/mozilla/zamboni/pull/2315","diff_url":"https://github.com/mozilla/zamboni/pull/2315.diff","patch_url":"https://github.com/mozilla/zamboni/pull/2315.patch","issue_url":"https://api.github.com/repos/mozilla/zamboni/issues/2315","number":2315,"state":"open","title":"feed es view (bug 1036216)","user":{"login":"ngokevin","id":674727,"avatar_url":"https://avatars.githubusercontent.com/u/674727?","gravatar_id":"f1fa62935c8064826634fc93ce7aa4bb","url":"https://api.github.com/users/ngokevin","html_url":"https://github.com/ngokevin","followers_url":"https://api.github.com/users/ngokevin/followers","following_url":"https://api.github.com/users/ngokevin/following{/other_user}","gists_url":"https://api.github.com/users/ngokevin/gists{/gist_id}","starred_url":"https://api.github.com/users/ngokevin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngokevin/subscriptions","organizations_url":"https://api.github.com/users/ngokevin/orgs","repos_url":"https://api.github.com/users/ngokevin/repos","events_url":"https://api.github.com/users/ngokevin/events{/privacy}","received_events_url":"https://api.github.com/users/ngokevin/received_events","type":"User","site_admin":false},"body":"Breaking https://github.com/mozilla/zamboni/pull/2298 up.\r\n\r\n- Do a filter on FeedItem by region that puts matching region/carrier operator shelves on top.\r\n- Do an OR query for FeedApp/Brand/Collection/Shelf using IDs\r\n- Do an OR query for apps using IDs\r\n\r\nRelies on [indexers](https://github.com/mozilla/zamboni/pull/2314) and [serializers](https://github.com/mozilla/zamboni/pull/2313).","created_at":"2014-07-14T18:08:25Z","updated_at":"2014-07-21T23:42:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dca6d7aded7c39398e0372b3d37760458050682c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/zamboni/pulls/2315/commits","review_comments_url":"https://api.github.com/repos/mozilla/zamboni/pulls/2315/comments","review_comment_url":"https://api.github.com/repos/mozilla/zamboni/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mozilla/zamboni/issues/2315/comments","statuses_url":"https://api.github.com/repos/mozilla/zamboni/statuses/6ebbcb80ebc244dc4a61522756a10e599a172481","head":{"label":"ngokevin:feedindexview","ref":"feedindexview","sha":"6ebbcb80ebc244dc4a61522756a10e599a172481","user":{"login":"ngokevin","id":674727,"avatar_url":"https://avatars.githubusercontent.com/u/674727?","gravatar_id":"f1fa62935c8064826634fc93ce7aa4bb","url":"https://api.github.com/users/ngokevin","html_url":"https://github.com/ngokevin","followers_url":"https://api.github.com/users/ngokevin/followers","following_url":"https://api.github.com/users/ngokevin/following{/other_user}","gists_url":"https://api.github.com/users/ngokevin/gists{/gist_id}","starred_url":"https://api.github.com/users/ngokevin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngokevin/subscriptions","organizations_url":"https://api.github.com/users/ngokevin/orgs","repos_url":"https://api.github.com/users/ngokevin/repos","events_url":"https://api.github.com/users/ngokevin/events{/privacy}","received_events_url":"https://api.github.com/users/ngokevin/received_events","type":"User","site_admin":false},"repo":{"id":4227957,"name":"zamboni","full_name":"ngokevin/zamboni","owner":{"login":"ngokevin","id":674727,"avatar_url":"https://avatars.githubusercontent.com/u/674727?","gravatar_id":"f1fa62935c8064826634fc93ce7aa4bb","url":"https://api.github.com/users/ngokevin","html_url":"https://github.com/ngokevin","followers_url":"https://api.github.com/users/ngokevin/followers","following_url":"https://api.github.com/users/ngokevin/following{/other_user}","gists_url":"https://api.github.com/users/ngokevin/gists{/gist_id}","starred_url":"https://api.github.com/users/ngokevin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngokevin/subscriptions","organizations_url":"https://api.github.com/users/ngokevin/orgs","repos_url":"https://api.github.com/users/ngokevin/repos","events_url":"https://api.github.com/users/ngokevin/events{/privacy}","received_events_url":"https://api.github.com/users/ngokevin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ngokevin/zamboni","description":"A clandestine operation to make AMO happy","fork":true,"url":"https://api.github.com/repos/ngokevin/zamboni","forks_url":"https://api.github.com/repos/ngokevin/zamboni/forks","keys_url":"https://api.github.com/repos/ngokevin/zamboni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ngokevin/zamboni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ngokevin/zamboni/teams","hooks_url":"https://api.github.com/repos/ngokevin/zamboni/hooks","issue_events_url":"https://api.github.com/repos/ngokevin/zamboni/issues/events{/number}","events_url":"https://api.github.com/repos/ngokevin/zamboni/events","assignees_url":"https://api.github.com/repos/ngokevin/zamboni/assignees{/user}","branches_url":"https://api.github.com/repos/ngokevin/zamboni/branches{/branch}","tags_url":"https://api.github.com/repos/ngokevin/zamboni/tags","blobs_url":"https://api.github.com/repos/ngokevin/zamboni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ngokevin/zamboni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ngokevin/zamboni/git/refs{/sha}","trees_url":"https://api.github.com/repos/ngokevin/zamboni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ngokevin/zamboni/statuses/{sha}","languages_url":"https://api.github.com/repos/ngokevin/zamboni/languages","stargazers_url":"https://api.github.com/repos/ngokevin/zamboni/stargazers","contributors_url":"https://api.github.com/repos/ngokevin/zamboni/contributors","subscribers_url":"https://api.github.com/repos/ngokevin/zamboni/subscribers","subscription_url":"https://api.github.com/repos/ngokevin/zamboni/subscription","commits_url":"https://api.github.com/repos/ngokevin/zamboni/commits{/sha}","git_commits_url":"https://api.github.com/repos/ngokevin/zamboni/git/commits{/sha}","comments_url":"https://api.github.com/repos/ngokevin/zamboni/comments{/number}","issue_comment_url":"https://api.github.com/repos/ngokevin/zamboni/issues/comments/{number}","contents_url":"https://api.github.com/repos/ngokevin/zamboni/contents/{+path}","compare_url":"https://api.github.com/repos/ngokevin/zamboni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ngokevin/zamboni/merges","archive_url":"https://api.github.com/repos/ngokevin/zamboni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ngokevin/zamboni/downloads","issues_url":"https://api.github.com/repos/ngokevin/zamboni/issues{/number}","pulls_url":"https://api.github.com/repos/ngokevin/zamboni/pulls{/number}","milestones_url":"https://api.github.com/repos/ngokevin/zamboni/milestones{/number}","notifications_url":"https://api.github.com/repos/ngokevin/zamboni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ngokevin/zamboni/labels{/name}","releases_url":"https://api.github.com/repos/ngokevin/zamboni/releases{/id}","created_at":"2012-05-04T18:44:23Z","updated_at":"2014-07-02T20:29:57Z","pushed_at":"2014-07-21T23:09:15Z","git_url":"git://github.com/ngokevin/zamboni.git","ssh_url":"git@github.com:ngokevin/zamboni.git","clone_url":"https://github.com/ngokevin/zamboni.git","svn_url":"https://github.com/ngokevin/zamboni","homepage":"http://mozilla.github.com/zamboni/","size":280789,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"bbb0ff2acb5ac43aab134738d14e7f0857f774d7","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?","gravatar_id":"9ba739c8f3288e256b13553e4d257b5e","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":347655,"name":"zamboni","full_name":"mozilla/zamboni","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?","gravatar_id":"9ba739c8f3288e256b13553e4d257b5e","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/zamboni","description":"The backend of the Firefox Marketplace","fork":false,"url":"https://api.github.com/repos/mozilla/zamboni","forks_url":"https://api.github.com/repos/mozilla/zamboni/forks","keys_url":"https://api.github.com/repos/mozilla/zamboni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/zamboni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/zamboni/teams","hooks_url":"https://api.github.com/repos/mozilla/zamboni/hooks","issue_events_url":"https://api.github.com/repos/mozilla/zamboni/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/zamboni/events","assignees_url":"https://api.github.com/repos/mozilla/zamboni/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/zamboni/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/zamboni/tags","blobs_url":"https://api.github.com/repos/mozilla/zamboni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/zamboni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/zamboni/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/zamboni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/zamboni/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/zamboni/languages","stargazers_url":"https://api.github.com/repos/mozilla/zamboni/stargazers","contributors_url":"https://api.github.com/repos/mozilla/zamboni/contributors","subscribers_url":"https://api.github.com/repos/mozilla/zamboni/subscribers","subscription_url":"https://api.github.com/repos/mozilla/zamboni/subscription","commits_url":"https://api.github.com/repos/mozilla/zamboni/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/zamboni/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/zamboni/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/zamboni/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla/zamboni/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/zamboni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/zamboni/merges","archive_url":"https://api.github.com/repos/mozilla/zamboni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/zamboni/downloads","issues_url":"https://api.github.com/repos/mozilla/zamboni/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/zamboni/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/zamboni/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/zamboni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/zamboni/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/zamboni/releases{/id}","created_at":"2009-10-23T19:35:34Z","updated_at":"2014-07-18T10:01:43Z","pushed_at":"2014-07-21T23:08:14Z","git_url":"git://github.com/mozilla/zamboni.git","ssh_url":"git@github.com:mozilla/zamboni.git","clone_url":"https://github.com/mozilla/zamboni.git","svn_url":"https://github.com/mozilla/zamboni","homepage":"http://zamboni.readthedocs.org","size":351404,"stargazers_count":420,"watchers_count":420,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":false,"forks_count":230,"mirror_url":null,"open_issues_count":14,"forks":230,"open_issues":14,"watchers":420,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/2315"},"html":{"href":"https://github.com/mozilla/zamboni/pull/2315"},"issue":{"href":"https://api.github.com/repos/mozilla/zamboni/issues/2315"},"comments":{"href":"https://api.github.com/repos/mozilla/zamboni/issues/2315/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/2315/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/2315/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/zamboni/statuses/6ebbcb80ebc244dc4a61522756a10e599a172481"}}}}