зеркало из https://github.com/mozilla/treeherder.git
change get_or_create_option_collection method in refdata
This commit is contained in:
Родитель
a0937c4120
Коммит
63ce4ab3a2
|
@ -6,25 +6,6 @@ class RefDataManager(TreeherderModelBase):
|
||||||
|
|
||||||
CONTENT_TYPES = ['jobs']
|
CONTENT_TYPES = ['jobs']
|
||||||
|
|
||||||
# TODO: discuss about dynamic methods generation
|
|
||||||
# def _get_generic(self, keys, proc):
|
|
||||||
|
|
||||||
# id_iter = self.sources["jobs"].dhub.execute(
|
|
||||||
# proc=proc,
|
|
||||||
# placeholders=keys,
|
|
||||||
# debug_show=self.DEBUG,
|
|
||||||
# return_type='iter')
|
|
||||||
|
|
||||||
# return id_iter.get_column_data('id')
|
|
||||||
|
|
||||||
# def _get_or_create_generic(self, keys, others, proc):
|
|
||||||
|
|
||||||
# self.sources["jobs"].dhub.execute(
|
|
||||||
# proc=proc,
|
|
||||||
# placeholders=keys+others+keys,
|
|
||||||
# debug_show=self.DEBUG)
|
|
||||||
# return self._get_generic_id(keys, proc)
|
|
||||||
|
|
||||||
def get_build_platform_id(self, os_name, platform, architecture):
|
def get_build_platform_id(self, os_name, platform, architecture):
|
||||||
|
|
||||||
id_iter = self.sources["jobs"].dhub.execute(
|
id_iter = self.sources["jobs"].dhub.execute(
|
||||||
|
@ -140,32 +121,50 @@ class RefDataManager(TreeherderModelBase):
|
||||||
|
|
||||||
return self.get_option_id(name)
|
return self.get_option_id(name)
|
||||||
|
|
||||||
def get_option_collection_id(self, option_collection_id, option_id):
|
def get_option_collection_id(self, options):
|
||||||
|
"""returns an option_collection_id given a list of options"""
|
||||||
|
options = sorted(list(options))
|
||||||
|
|
||||||
id_iter = self.sources["jobs"].dhub.execute(
|
id_iter = self.sources["jobs"].dhub.execute(
|
||||||
proc='reference.selects.get_option_collection_id',
|
proc='reference.selects.get_option_collection_id',
|
||||||
placeholders=[option_collection_id, option_id],
|
placeholders=[','.join(options)],
|
||||||
debug_show=self.DEBUG,
|
debug_show=self.DEBUG,
|
||||||
return_type='iter')
|
return_type='iter')
|
||||||
|
|
||||||
return id_iter.get_column_data('id')
|
return id_iter.get_column_data('id')
|
||||||
|
|
||||||
def get_or_create_option_collection(self, option_collection_id,
|
def get_last_collection_id(self):
|
||||||
option_id):
|
|
||||||
|
|
||||||
self.sources["jobs"].dhub.execute(
|
self.sources["jobs"].dhub.execute(
|
||||||
proc='reference.inserts.create_option_collection',
|
proc='reference.selects.get_last_collection_id',
|
||||||
placeholders=[
|
placeholders=[],
|
||||||
option_collection_id,
|
|
||||||
option_id,
|
|
||||||
option_collection_id,
|
|
||||||
option_id
|
|
||||||
],
|
|
||||||
debug_show=self.DEBUG)
|
debug_show=self.DEBUG)
|
||||||
|
|
||||||
return self.get_option_collection_id(
|
def get_or_create_option_collection(self, options):
|
||||||
option_collection_id,
|
|
||||||
option_id)
|
#check if this collection already exists
|
||||||
|
id = self.get_option_collection_id(options)
|
||||||
|
if not id:
|
||||||
|
|
||||||
|
#retrieve the last collection
|
||||||
|
option_collection_id = self.get_last_collection_id() + 1
|
||||||
|
for option in options:
|
||||||
|
|
||||||
|
#create an option if it doesn't exist
|
||||||
|
option_id = self.get_or_create_option(option,
|
||||||
|
'description needed')
|
||||||
|
|
||||||
|
# create an entry in option_collection
|
||||||
|
self.sources["jobs"].dhub.execute(
|
||||||
|
proc='reference.inserts.create_option_collection',
|
||||||
|
placeholders=[
|
||||||
|
option_collection_id,
|
||||||
|
option_id,
|
||||||
|
option_collection_id,
|
||||||
|
option_id
|
||||||
|
],
|
||||||
|
debug_show=self.DEBUG)
|
||||||
|
id = self.get_option_collection_id(options)
|
||||||
|
return id
|
||||||
|
|
||||||
def get_product_id(self, name):
|
def get_product_id(self, name):
|
||||||
|
|
||||||
|
|
|
@ -130,10 +130,18 @@
|
||||||
AND `active_status` = 'active'",
|
AND `active_status` = 'active'",
|
||||||
"host":"read_host"
|
"host":"read_host"
|
||||||
},
|
},
|
||||||
|
"get_last_collection_id":{
|
||||||
|
"sql": "SELECT MAX(`collection_id`)
|
||||||
|
FROM `option_collection`",
|
||||||
|
"host":"read_host"
|
||||||
|
},
|
||||||
"get_option_collection_id":{
|
"get_option_collection_id":{
|
||||||
"sql": "SELECT `id`
|
"sql": "SELECT `option_collection_id`
|
||||||
FROM `option_collection`
|
FROM `option_collection` oc
|
||||||
WHERE `option_collection_id` = ? AND `option_id` = ?",
|
INNER JOIN `option` o on o.id = oc.option_id
|
||||||
|
GROUP BY `option_collection_id`
|
||||||
|
HAVING
|
||||||
|
GROUP_CONCAT(o.name ORDER BY o.name ASC SEPARATOR ',') = ?",
|
||||||
"host":"read_host"
|
"host":"read_host"
|
||||||
},
|
},
|
||||||
"get_product_id":{
|
"get_product_id":{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче