blob: 1da9975566aa8ce81a7552078f133fe43bba8543 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6"""A servlet that implements the backend of issues search.
7
8The GET request to a backend search has the same query string
9parameters as the issue list servlet. But, instead of rendering a
10HTML page, the backend search handler returns a JSON response with a
11list of matching, sorted issue IID numbers from this shard that are
12viewable by the requesting user.
13
14Each backend search request works within a single shard. Each
15besearch backend job can access any single shard while processing a request.
16
17The current user ID must be passed in from the frontend for permission
18checking. The user ID for the special "me" term can also be passed in
19(so that you can view another user's dashboard and "me" will refer to
20them).
21"""
22from __future__ import print_function
23from __future__ import division
24from __future__ import absolute_import
25
26import logging
27import time
28
29from framework import jsonfeed
30from search import backendsearchpipeline
31from tracker import tracker_constants
32
33
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020034# Change to FlaskInternalTask
Copybara854996b2021-09-07 19:36:02 +000035class BackendSearch(jsonfeed.InternalTask):
36 """JSON servlet for issue search in a GAE backend."""
37
38 CHECK_SAME_APP = True
39 _DEFAULT_RESULTS_PER_PAGE = tracker_constants.DEFAULT_RESULTS_PER_PAGE
40
41 def HandleRequest(self, mr):
42 """Search for issues and respond with the IIDs of matching issues.
43
44 Args:
45 mr: common information parsed from the HTTP request.
46
47 Returns:
48 Results dictionary in JSON format.
49 """
50 # Users are never logged into backends, so the frontends tell us.
51 logging.info('query_project_names is %r', mr.query_project_names)
52 pipeline = backendsearchpipeline.BackendSearchPipeline(
53 mr, self.services, self._DEFAULT_RESULTS_PER_PAGE,
54 mr.query_project_names, mr.specified_logged_in_user_id,
55 mr.specified_me_user_ids)
56 pipeline.SearchForIIDs()
57
58 start = time.time()
59 # Backends work in parallel to precache issues that the
60 # frontend is very likely to need.
61 _prefetched_issues = self.services.issue.GetIssues(
62 mr.cnxn, pipeline.result_iids[:mr.start + mr.num],
63 shard_id=mr.shard_id)
64 logging.info('prefetched and memcached %d issues in %d ms',
65 len(pipeline.result_iids[:mr.start + mr.num]),
66 int(1000 * (time.time() - start)))
67
68 if pipeline.error:
69 error_message = pipeline.error.message
70 else:
71 error_message = None
72
73 return {
74 'unfiltered_iids': pipeline.result_iids,
75 'search_limit_reached': pipeline.search_limit_reached,
76 'error': error_message,
77 }
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020078
79 # def GetBackendSearch(self, **kwargs):
80 # return self.handler(**kwargs)
81
82 # def PostBackendSearch(self, **kwargs):
83 # return self.handler(**kwargs)