mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP]: runbot: improve create performances.
This commit is contained in:
parent
9556723617
commit
3f997cff25
@ -195,21 +195,20 @@ class runbot_build(models.Model):
|
|||||||
|
|
||||||
@api.model_create_single
|
@api.model_create_single
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
branch = self.env['runbot.branch'].search([('id', '=', vals.get('branch_id', False))]) # branche 10174?
|
if not 'config_id' in vals:
|
||||||
if branch.no_build:
|
branch = self.env['runbot.branch'].browse(vals.get('branch_id'))
|
||||||
return self.env['runbot.build']
|
vals['config_id'] = branch.config_id.id
|
||||||
vals['config_id'] = vals['config_id'] if 'config_id' in vals else branch.config_id.id
|
|
||||||
build_id = super(runbot_build, self).create(vals)
|
build_id = super(runbot_build, self).create(vals)
|
||||||
extra_info = {'sequence': build_id.id if not build_id.sequence else build_id.sequence}
|
extra_info = {}
|
||||||
context = self.env.context
|
if not build_id.sequence:
|
||||||
|
extra_info['sequence'] = build_id.id
|
||||||
|
|
||||||
# compute dependencies
|
# compute dependencies
|
||||||
repo = build_id.repo_id
|
repo = build_id.repo_id
|
||||||
dep_create_vals = []
|
dep_create_vals = []
|
||||||
nb_deps = len(repo.dependency_ids)
|
|
||||||
params = build_id._get_params()
|
|
||||||
build_id._log('create', 'Build created') # mainly usefull to log creation time
|
build_id._log('create', 'Build created') # mainly usefull to log creation time
|
||||||
if not vals.get('dependency_ids'):
|
if not vals.get('dependency_ids'):
|
||||||
|
params = build_id._get_params() # calling git show, dont call that if not usefull.
|
||||||
for extra_repo in repo.dependency_ids:
|
for extra_repo in repo.dependency_ids:
|
||||||
repo_name = extra_repo.short_name
|
repo_name = extra_repo.short_name
|
||||||
last_commit = params['dep'][repo_name] # not name
|
last_commit = params['dep'][repo_name] # not name
|
||||||
@ -238,11 +237,10 @@ class runbot_build(models.Model):
|
|||||||
'dependency_hash': last_commit,
|
'dependency_hash': last_commit,
|
||||||
'match_type': match_type,
|
'match_type': match_type,
|
||||||
})
|
})
|
||||||
|
for dep_vals in dep_create_vals:
|
||||||
|
self.env['runbot.build.dependency'].sudo().create(dep_vals)
|
||||||
|
|
||||||
for dep_vals in dep_create_vals:
|
if not self.env.context.get('force_rebuild') and not vals.get('build_type') == 'rebuild':
|
||||||
self.env['runbot.build.dependency'].sudo().create(dep_vals)
|
|
||||||
|
|
||||||
if not context.get('force_rebuild') and not vals.get('build_type') == 'rebuild':
|
|
||||||
# detect duplicate
|
# detect duplicate
|
||||||
duplicate_id = None
|
duplicate_id = None
|
||||||
domain = [
|
domain = [
|
||||||
@ -257,6 +255,8 @@ class runbot_build(models.Model):
|
|||||||
('config_data', '=', build_id.config_data or False),
|
('config_data', '=', build_id.config_data or False),
|
||||||
]
|
]
|
||||||
candidates = self.search(domain)
|
candidates = self.search(domain)
|
||||||
|
|
||||||
|
nb_deps = len(repo.dependency_ids)
|
||||||
if candidates and nb_deps:
|
if candidates and nb_deps:
|
||||||
# check that all depedencies are matching.
|
# check that all depedencies are matching.
|
||||||
|
|
||||||
@ -296,7 +296,9 @@ class runbot_build(models.Model):
|
|||||||
continue
|
continue
|
||||||
docker_source_folders.add(docker_source_folder)
|
docker_source_folders.add(docker_source_folder)
|
||||||
|
|
||||||
build_id.write(extra_info)
|
if extra_info:
|
||||||
|
build_id.write(extra_info)
|
||||||
|
|
||||||
if build_id.local_state == 'duplicate' and build_id.duplicate_id.global_state in ('running', 'done'):
|
if build_id.local_state == 'duplicate' and build_id.duplicate_id.global_state in ('running', 'done'):
|
||||||
build_id._github_status()
|
build_id._github_status()
|
||||||
return build_id
|
return build_id
|
||||||
@ -307,7 +309,6 @@ class runbot_build(models.Model):
|
|||||||
build_by_old_values = defaultdict(lambda: self.env['runbot.build'])
|
build_by_old_values = defaultdict(lambda: self.env['runbot.build'])
|
||||||
for record in self:
|
for record in self:
|
||||||
build_by_old_values[record.local_state] += record
|
build_by_old_values[record.local_state] += record
|
||||||
assert 'state' not in values
|
|
||||||
local_result = values.get('local_result')
|
local_result = values.get('local_result')
|
||||||
for build in self:
|
for build in self:
|
||||||
assert not local_result or local_result == self._get_worst_result([build.local_result, local_result]) # dont write ok on a warn/error build
|
assert not local_result or local_result == self._get_worst_result([build.local_result, local_result]) # dont write ok on a warn/error build
|
||||||
|
@ -290,15 +290,6 @@ class Test_Build(RunbotCase):
|
|||||||
})
|
})
|
||||||
self.assertEqual(build.config_id, self.branch.config_id, "config_id should be the same as the branch")
|
self.assertEqual(build.config_id, self.branch.config_id, "config_id should be the same as the branch")
|
||||||
|
|
||||||
def test_build_from_branch_no_build(self):
|
|
||||||
"""test build is not even created when branch no_build is True"""
|
|
||||||
self.branch.no_build = True
|
|
||||||
build = self.create_build({
|
|
||||||
'branch_id': self.branch.id,
|
|
||||||
'name': 'd0d0caca0000ffffffffffffffffffffffffffff',
|
|
||||||
})
|
|
||||||
self.assertEqual(build, self.Build, "build should be an empty recordset")
|
|
||||||
|
|
||||||
def test_build_config_can_be_set(self):
|
def test_build_config_can_be_set(self):
|
||||||
"""test build config_id can be set to something different than the one on the branch"""
|
"""test build config_id can be set to something different than the one on the branch"""
|
||||||
self.branch.config_id = self.env.ref('runbot.runbot_build_config_default')
|
self.branch.config_id = self.env.ref('runbot.runbot_build_config_default')
|
||||||
|
Loading…
Reference in New Issue
Block a user