##// END OF EJS Templates
pull-requests: limit the ammount of data saved in default reviewers data for better memory usage...
marcink -
r4509:b5299f6d stable
parent child Browse files
Show More
@@ -18,7 +18,7 b''
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 from rhodecode.lib import helpers as h
21 from rhodecode.lib import helpers as h, rc_cache
22 22 from rhodecode.lib.utils2 import safe_int
23 23 from rhodecode.model.pull_request import get_diff_info
24 24 from rhodecode.model.db import PullRequestReviewers
@@ -54,20 +54,36 b' def reviewer_as_json(user, reasons=None,'
54 54 }
55 55
56 56
57 def get_default_reviewers_data(current_user, source_repo, source_commit, target_repo, target_commit):
57 def to_reviewers(e):
58 if isinstance(e, (tuple, list)):
59 return map(reviewer_as_json, e)
60 else:
61 return reviewer_as_json(e)
62
63
64 def get_default_reviewers_data(current_user, source_repo, source_ref, target_repo, target_ref,
65 include_diff_info=True):
58 66 """
59 67 Return json for default reviewers of a repository
60 68 """
61 69
62 diff_info = get_diff_info(
63 source_repo, source_commit.raw_id, target_repo, target_commit.raw_id)
70 diff_info = {}
71 if include_diff_info:
72 diff_info = get_diff_info(
73 source_repo, source_ref.commit_id, target_repo, target_ref.commit_id)
64 74
65 75 reasons = ['Default reviewer', 'Repository owner']
66 76 json_reviewers = [reviewer_as_json(
67 77 user=target_repo.user, reasons=reasons, mandatory=False, rules=None, role=None)]
68 78
79 compute_key = rc_cache.utils.compute_key_from_params(
80 current_user.user_id, source_repo.repo_id, source_ref.type, source_ref.name,
81 source_ref.commit_id, target_repo.repo_id, target_ref.type, target_ref.name,
82 target_ref.commit_id)
83
69 84 return {
70 85 'api_ver': REVIEWER_API_VERSION, # define version for later possible schema upgrade
86 'compute_key': compute_key,
71 87 'diff_info': diff_info,
72 88 'reviewers': json_reviewers,
73 89 'rules': {},
@@ -40,7 +40,7 b' from rhodecode.lib.auth import ('
40 40 LoginRequired, HasRepoPermissionAny, HasRepoPermissionAnyDecorator,
41 41 NotAnonymous, CSRFRequired)
42 42 from rhodecode.lib.utils2 import str2bool, safe_str, safe_unicode, safe_int, aslist
43 from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason
43 from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason, Reference
44 44 from rhodecode.lib.vcs.exceptions import (
45 45 CommitDoesNotExistError, RepositoryRequirementError, EmptyRepositoryError)
46 46 from rhodecode.model.changeset_status import ChangesetStatusModel
@@ -1150,8 +1150,9 b' class RepoPullRequestsView(RepoAppView, '
1150 1150 ancestor = source_scm.get_common_ancestor(
1151 1151 source_commit.raw_id, target_commit.raw_id, target_scm)
1152 1152
1153 source_ref_type, source_ref_name, source_commit_id = _form['target_ref'].split(':')
1154 target_ref_type, target_ref_name, target_commit_id = _form['source_ref'].split(':')
1153 1155 # recalculate target ref based on ancestor
1154 target_ref_type, target_ref_name, __ = _form['target_ref'].split(':')
1155 1156 target_ref = ':'.join((target_ref_type, target_ref_name, ancestor))
1156 1157
1157 1158 get_default_reviewers_data, validate_default_reviewers, validate_observers = \
@@ -1159,8 +1160,12 b' class RepoPullRequestsView(RepoAppView, '
1159 1160
1160 1161 # recalculate reviewers logic, to make sure we can validate this
1161 1162 reviewer_rules = get_default_reviewers_data(
1162 self._rhodecode_db_user, source_db_repo,
1163 source_commit, target_db_repo, target_commit)
1163 self._rhodecode_db_user,
1164 source_db_repo,
1165 Reference(source_ref_type, source_ref_name, source_commit_id),
1166 target_db_repo,
1167 Reference(target_ref_type, target_ref_name, target_commit_id),
1168 include_diff_info=False)
1164 1169
1165 1170 reviewers = validate_default_reviewers(_form['review_members'], reviewer_rules)
1166 1171 observers = validate_observers(_form['observer_members'], reviewer_rules)
@@ -25,6 +25,7 b' from pyramid.view import view_config'
25 25 from rhodecode.apps._base import RepoAppView
26 26 from rhodecode.apps.repository.utils import get_default_reviewers_data
27 27 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
28 from rhodecode.lib.vcs.backends.base import Reference
28 29 from rhodecode.model.db import Repository
29 30
30 31 log = logging.getLogger(__name__)
@@ -61,13 +62,19 b' class RepoReviewRulesView(RepoAppView):'
61 62 target_repo_name = request.GET.get('target_repo', source_repo_name)
62 63 target_repo = Repository.get_by_repo_name(target_repo_name)
63 64
64 source_ref = request.GET['source_ref']
65 target_ref = request.GET['target_ref']
66 source_commit = source_repo.get_commit(source_ref)
67 target_commit = target_repo.get_commit(target_ref)
65 current_user = request.user.get_instance()
66
67 source_commit_id = request.GET['source_ref']
68 source_type = request.GET['source_ref_type']
69 source_name = request.GET['source_ref_name']
68 70
69 current_user = request.user.get_instance()
71 target_commit_id = request.GET['target_ref']
72 target_type = request.GET['target_ref_type']
73 target_name = request.GET['target_ref_name']
74
75 source_ref = Reference(source_type, source_name, source_commit_id)
76 target_ref = Reference(target_type, target_name, target_commit_id)
77
70 78 review_data = get_default_reviewers_data(
71 current_user, source_repo, source_commit, target_repo, target_commit)
72
79 current_user, source_repo, source_ref, target_repo, target_ref)
73 80 return review_data
@@ -57,7 +57,20 b' FILEMODE_DEFAULT = 0o100644'
57 57 FILEMODE_EXECUTABLE = 0o100755
58 58 EMPTY_COMMIT_ID = '0' * 40
59 59
60 Reference = collections.namedtuple('Reference', ('type', 'name', 'commit_id'))
60 _Reference = collections.namedtuple('Reference', ('type', 'name', 'commit_id'))
61
62
63 class Reference(_Reference):
64
65 @property
66 def branch(self):
67 if self.type == 'branch':
68 return self.name
69
70 @property
71 def bookmark(self):
72 if self.type == 'book':
73 return self.name
61 74
62 75
63 76 class MergeFailureReason(object):
@@ -710,7 +710,7 b' class PullRequestModel(BaseModel):'
710 710 MergeCheck.validate(
711 711 pull_request, auth_user=auth_user, translator=translator)
712 712
713 self.notify_reviewers(pull_request, reviewer_ids)
713 self.notify_reviewers(pull_request, reviewer_ids, created_by_user)
714 714 self.trigger_pull_request_hook(pull_request, created_by_user, 'create')
715 715
716 716 creation_data = pull_request.get_api_data(with_merge_state=False)
@@ -313,9 +313,13 b' window.ReviewersController = function ()'
313 313 {
314 314 'repo_name': templateContext.repo_name,
315 315 'source_repo': sourceRepo,
316 'source_ref_type': sourceRef[0],
317 'source_ref_name': sourceRef[1],
316 318 'source_ref': sourceRef[2],
317 319 'target_repo': targetRepo,
318 'target_ref': targetRef[2]
320 'target_ref': targetRef[2],
321 'target_ref_type': sourceRef[0],
322 'target_ref_name': sourceRef[1]
319 323 });
320 324
321 325 self.currentRequest = $.ajax({
General Comments 0
You need to be logged in to leave comments. Login now