##// 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 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
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 from rhodecode.lib.utils2 import safe_int
22 from rhodecode.lib.utils2 import safe_int
23 from rhodecode.model.pull_request import get_diff_info
23 from rhodecode.model.pull_request import get_diff_info
24 from rhodecode.model.db import PullRequestReviewers
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 Return json for default reviewers of a repository
67 Return json for default reviewers of a repository
60 """
68 """
61
69
70 diff_info = {}
71 if include_diff_info:
62 diff_info = get_diff_info(
72 diff_info = get_diff_info(
63 source_repo, source_commit.raw_id, target_repo, target_commit.raw_id)
73 source_repo, source_ref.commit_id, target_repo, target_ref.commit_id)
64
74
65 reasons = ['Default reviewer', 'Repository owner']
75 reasons = ['Default reviewer', 'Repository owner']
66 json_reviewers = [reviewer_as_json(
76 json_reviewers = [reviewer_as_json(
67 user=target_repo.user, reasons=reasons, mandatory=False, rules=None, role=None)]
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 return {
84 return {
70 'api_ver': REVIEWER_API_VERSION, # define version for later possible schema upgrade
85 'api_ver': REVIEWER_API_VERSION, # define version for later possible schema upgrade
86 'compute_key': compute_key,
71 'diff_info': diff_info,
87 'diff_info': diff_info,
72 'reviewers': json_reviewers,
88 'reviewers': json_reviewers,
73 'rules': {},
89 'rules': {},
@@ -40,7 +40,7 b' from rhodecode.lib.auth import ('
40 LoginRequired, HasRepoPermissionAny, HasRepoPermissionAnyDecorator,
40 LoginRequired, HasRepoPermissionAny, HasRepoPermissionAnyDecorator,
41 NotAnonymous, CSRFRequired)
41 NotAnonymous, CSRFRequired)
42 from rhodecode.lib.utils2 import str2bool, safe_str, safe_unicode, safe_int, aslist
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 from rhodecode.lib.vcs.exceptions import (
44 from rhodecode.lib.vcs.exceptions import (
45 CommitDoesNotExistError, RepositoryRequirementError, EmptyRepositoryError)
45 CommitDoesNotExistError, RepositoryRequirementError, EmptyRepositoryError)
46 from rhodecode.model.changeset_status import ChangesetStatusModel
46 from rhodecode.model.changeset_status import ChangesetStatusModel
@@ -1150,8 +1150,9 b' class RepoPullRequestsView(RepoAppView, '
1150 ancestor = source_scm.get_common_ancestor(
1150 ancestor = source_scm.get_common_ancestor(
1151 source_commit.raw_id, target_commit.raw_id, target_scm)
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 # recalculate target ref based on ancestor
1155 # recalculate target ref based on ancestor
1154 target_ref_type, target_ref_name, __ = _form['target_ref'].split(':')
1155 target_ref = ':'.join((target_ref_type, target_ref_name, ancestor))
1156 target_ref = ':'.join((target_ref_type, target_ref_name, ancestor))
1156
1157
1157 get_default_reviewers_data, validate_default_reviewers, validate_observers = \
1158 get_default_reviewers_data, validate_default_reviewers, validate_observers = \
@@ -1159,8 +1160,12 b' class RepoPullRequestsView(RepoAppView, '
1159
1160
1160 # recalculate reviewers logic, to make sure we can validate this
1161 # recalculate reviewers logic, to make sure we can validate this
1161 reviewer_rules = get_default_reviewers_data(
1162 reviewer_rules = get_default_reviewers_data(
1162 self._rhodecode_db_user, source_db_repo,
1163 self._rhodecode_db_user,
1163 source_commit, target_db_repo, target_commit)
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 reviewers = validate_default_reviewers(_form['review_members'], reviewer_rules)
1170 reviewers = validate_default_reviewers(_form['review_members'], reviewer_rules)
1166 observers = validate_observers(_form['observer_members'], reviewer_rules)
1171 observers = validate_observers(_form['observer_members'], reviewer_rules)
@@ -25,6 +25,7 b' from pyramid.view import view_config'
25 from rhodecode.apps._base import RepoAppView
25 from rhodecode.apps._base import RepoAppView
26 from rhodecode.apps.repository.utils import get_default_reviewers_data
26 from rhodecode.apps.repository.utils import get_default_reviewers_data
27 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
28 from rhodecode.lib.vcs.backends.base import Reference
28 from rhodecode.model.db import Repository
29 from rhodecode.model.db import Repository
29
30
30 log = logging.getLogger(__name__)
31 log = logging.getLogger(__name__)
@@ -61,13 +62,19 b' class RepoReviewRulesView(RepoAppView):'
61 target_repo_name = request.GET.get('target_repo', source_repo_name)
62 target_repo_name = request.GET.get('target_repo', source_repo_name)
62 target_repo = Repository.get_by_repo_name(target_repo_name)
63 target_repo = Repository.get_by_repo_name(target_repo_name)
63
64
64 source_ref = request.GET['source_ref']
65 current_user = request.user.get_instance()
65 target_ref = request.GET['target_ref']
66
66 source_commit = source_repo.get_commit(source_ref)
67 source_commit_id = request.GET['source_ref']
67 target_commit = target_repo.get_commit(target_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 review_data = get_default_reviewers_data(
78 review_data = get_default_reviewers_data(
71 current_user, source_repo, source_commit, target_repo, target_commit)
79 current_user, source_repo, source_ref, target_repo, target_ref)
72
73 return review_data
80 return review_data
@@ -57,7 +57,20 b' FILEMODE_DEFAULT = 0o100644'
57 FILEMODE_EXECUTABLE = 0o100755
57 FILEMODE_EXECUTABLE = 0o100755
58 EMPTY_COMMIT_ID = '0' * 40
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 class MergeFailureReason(object):
76 class MergeFailureReason(object):
@@ -710,7 +710,7 b' class PullRequestModel(BaseModel):'
710 MergeCheck.validate(
710 MergeCheck.validate(
711 pull_request, auth_user=auth_user, translator=translator)
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 self.trigger_pull_request_hook(pull_request, created_by_user, 'create')
714 self.trigger_pull_request_hook(pull_request, created_by_user, 'create')
715
715
716 creation_data = pull_request.get_api_data(with_merge_state=False)
716 creation_data = pull_request.get_api_data(with_merge_state=False)
@@ -313,9 +313,13 b' window.ReviewersController = function ()'
313 {
313 {
314 'repo_name': templateContext.repo_name,
314 'repo_name': templateContext.repo_name,
315 'source_repo': sourceRepo,
315 'source_repo': sourceRepo,
316 'source_ref_type': sourceRef[0],
317 'source_ref_name': sourceRef[1],
316 'source_ref': sourceRef[2],
318 'source_ref': sourceRef[2],
317 'target_repo': targetRepo,
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 self.currentRequest = $.ajax({
325 self.currentRequest = $.ajax({
General Comments 0
You need to be logged in to leave comments. Login now