diff options
author | Michael Wood <michael.g.wood@intel.com> | 2015-09-29 10:50:10 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-09-29 13:45:06 +0100 |
commit | 505979ab931e3a2a218d7030d6064987e8f9ff14 (patch) | |
tree | 4d5551e5ef3e339d560b55ed4574b0517bc55262 /lib | |
parent | 46b119eb62a5a612fe4c0847862d34f408e556f7 (diff) | |
download | bitbake-505979ab931e3a2a218d7030d6064987e8f9ff14.zip |
toaster: orm remove the complicated querying on the ORM
We no longer need to compute each layer_version and all the recipes
which belong to this.
[YOCTO #8147]
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/toaster/orm/models.py | 49 | ||||
-rw-r--r-- | lib/toaster/toastergui/tables.py | 2 | ||||
-rw-r--r-- | lib/toaster/toastergui/typeaheads.py | 5 |
3 files changed, 34 insertions, 22 deletions
diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py index 9a052bf7..5aed158c 100644 --- a/lib/toaster/orm/models.py +++ b/lib/toaster/orm/models.py @@ -191,6 +191,7 @@ class Project(models.Model): # returns a queryset of compatible layers for a project def compatible_layerversions(self, release = None, layer_name = None): + logger.warning("This function is deprecated") if release == None: release = self.release # layers on the same branch or layers specifically set for this project @@ -205,45 +206,55 @@ class Project(models.Model): return queryset - def projectlayer_equivalent_set(self): - return self.compatible_layerversions().filter(layer__name__in = [x.layercommit.layer.name for x in self.projectlayer_set.all()]).select_related("up_branch") + def get_all_compatible_layer_versions(self): + """ Returns Queryset of all Layer_Versions which are compatible with + this project""" + queryset = Layer_Version.objects.filter( + (Q(up_branch__name=self.release.branch_name) & Q(build=None)) + | Q(project=self)) + + return queryset + + def get_project_layer_versions(self, pk=False): + """ Returns the Layer_Versions currently added to this project """ + layer_versions = self.projectlayer_set.all().values('layercommit') + + if pk is False: + return layer_versions + else: + return layer_versions.values_list('pk', flat=True) + def get_available_machines(self): """ Returns QuerySet of all Machines which are provided by the Layers currently added to the Project """ - queryset = Machine.objects.filter(layer_version__in=self.projectlayer_equivalent_set) + queryset = Machine.objects.filter( + layer_version__in=self.get_project_layer_versions(self)) + return queryset def get_all_compatible_machines(self): """ Returns QuerySet of all the compatible machines available to the project including ones from Layers not currently added """ - compatible_layers = self.compatible_layerversions() + queryset = Machine.objects.filter( + layer_version__in=self.get_all_compatible_layer_versions()) - queryset = Machine.objects.filter(layer_version__in=compatible_layers) return queryset def get_available_recipes(self): - """ Returns QuerySet of all Recipes which are provided by the Layers - currently added to the Project """ - project_layers = self.projectlayer_equivalent_set() - queryset = Recipe.objects.filter(layer_version__in = project_layers) - - # Copied from get_all_compatible_recipes - search_maxids = map(lambda i: i[0], list(queryset.values('name').distinct().annotate(max_id=Max('id')).values_list('max_id'))) - queryset = queryset.filter(id__in=search_maxids).select_related('layer_version', 'layer_version__layer', 'layer_version__up_branch', 'layer_source') - # End copy + """ Returns QuerySet of all the recipes that are provided by layers + added to this project """ + queryset = Recipe.objects.filter( + layer_version__in=self.get_project_layer_versions()) return queryset def get_all_compatible_recipes(self): """ Returns QuerySet of all the compatible Recipes available to the project including ones from Layers not currently added """ - compatible_layerversions = self.compatible_layerversions() - queryset = Recipe.objects.filter(layer_version__in = compatible_layerversions) - - search_maxids = map(lambda i: i[0], list(queryset.values('name').distinct().annotate(max_id=Max('id')).values_list('max_id'))) + queryset = Recipe.objects.filter( + layer_version__in=self.get_all_compatible_layer_versions()) - queryset = queryset.filter(id__in=search_maxids).select_related('layer_version', 'layer_version__layer', 'layer_version__up_branch', 'layer_source') return queryset diff --git a/lib/toaster/toastergui/tables.py b/lib/toaster/toastergui/tables.py index 3354072e..5cc04a23 100644 --- a/lib/toaster/toastergui/tables.py +++ b/lib/toaster/toastergui/tables.py @@ -221,7 +221,7 @@ class MachinesTable(ToasterTable, ProjectFiltersMixin): def setup_filters(self, *args, **kwargs): project = Project.objects.get(pk=kwargs['pid']) - self.project_layers = project.projectlayer_equivalent_set() + self.project_layers = project.get_project_layer_versions() self.add_filter(title="Filter by project machines", name="in_current_project", diff --git a/lib/toaster/toastergui/typeaheads.py b/lib/toaster/toastergui/typeaheads.py index d5bec58e..9db31827 100644 --- a/lib/toaster/toastergui/typeaheads.py +++ b/lib/toaster/toastergui/typeaheads.py @@ -27,7 +27,7 @@ class LayersTypeAhead(ToasterTypeAhead): super(LayersTypeAhead, self).__init__() def apply_search(self, search_term, prj, request): - layers = prj.compatible_layerversions() + layers = prj.get_all_compatible_layer_versions() layers = layers.order_by('layer__name') # Unlike the other typeaheads we also don't want to show suggestions @@ -35,7 +35,8 @@ class LayersTypeAhead(ToasterTypeAhead): # layerdeps to a new layer. if ("include_added" in request.GET and request.GET['include_added'] != "true"): - layers = layers.exclude(pk__in=prj.projectlayer_equivalent_set) + layers = layers.exclude( + pk__in=prj.get_project_layer_versions(pk=True)) primary_results = layers.filter(layer__name__istartswith=search_term) secondary_results = layers.filter(layer__name__icontains=search_term).exclude(pk__in=primary_results) |