From: Michael Wood <michael.g.wood@intel.com>
To: bitbake-devel@lists.openembedded.org
Subject: Re: [PATCH v2 22/22] toaster: orm remove the complicated querying on the ORM
Date: Tue, 29 Sep 2015 10:54:12 +0100 [thread overview]
Message-ID: <560A5FC4.7050304@intel.com> (raw)
In-Reply-To: <1443520210-4276-1-git-send-email-michael.g.wood@intel.com>
On 29/09/15 10:50, Michael Wood wrote:
> 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>
> ---
> lib/toaster/orm/models.py | 49 ++++++++++++++++++++++--------------
> lib/toaster/toastergui/tables.py | 2 +-
> 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 9a052bf..5aed158 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 3354072..5cc04a2 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 d5bec58..9db3182 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)
We had a bit of a race condition on creating the pull request, this last
patch was updated in the original branch but the submission branch was
branched just before, hence v2 here.
Thanks,
Michael
prev parent reply other threads:[~2015-09-29 9:54 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-29 4:45 [PATCH 00/22] image customization brian avery
2015-09-29 4:45 ` [PATCH 01/22] toaster: make a workaround for old style index brian avery
2015-09-29 4:45 ` [PATCH 02/22] toaster: tables Move the title and name into the widget brian avery
2015-09-29 4:45 ` [PATCH 03/22] toaster: create custom layer and recipes for Image customisation brian avery
2015-09-29 4:45 ` [PATCH 04/22] toaster: widgets ToasterTable add logger to notify when cache hit brian avery
2015-09-29 4:45 ` [PATCH 05/22] toaster: widgets ToasterTable Add more info to search field exception brian avery
2015-09-29 4:45 ` [PATCH 06/22] toaster: add nocache option to the ToasterTable widget brian avery
2015-09-29 4:45 ` [PATCH 07/22] toaster: ToasterTable remove unused class definition brian avery
2015-09-29 4:45 ` [PATCH 08/22] toaster: Add CustomImageRecipe model brian avery
2015-09-29 4:45 ` [PATCH 09/22] toaster: add toggle for enabling image customisation feeature brian avery
2015-09-29 4:45 ` [PATCH 10/22] toaster: implement decorator for REST responses brian avery
2015-09-29 4:45 ` [PATCH 11/22] toaster: Fix indentation of jsunittests view brian avery
2015-09-29 4:45 ` [PATCH 12/22] toaster: Add new ReST API for Image Customisation feature brian avery
2015-09-29 4:45 ` [PATCH 13/22] toaster: Add ToasterTables for Image customisation feature brian avery
2015-09-29 4:45 ` [PATCH 14/22] toaster: Add Image customisation frontend feature brian avery
2015-09-29 4:45 ` [PATCH 15/22] toaster: Add test cases for new Image customisation features brian avery
2015-09-29 4:45 ` [PATCH 16/22] toaster: Special case the openembedded-core layer to avoid duplicates brian avery
2015-09-29 4:45 ` [PATCH 17/22] toaster: Create a relationship between build information and toaster layers brian avery
2015-09-29 4:45 ` [PATCH 18/22] toaster: Prioroitise the layer more generic vcs reference over the sha brian avery
2015-09-29 4:45 ` [PATCH 19/22] toaster: tables show all recipes in the layerdetails even duplicates brian avery
2015-09-29 4:45 ` [PATCH 20/22] toaster: buildinfohelper Create a copy of the built layer and recipe brian avery
2015-09-29 4:45 ` [PATCH 21/22] Revert "bitbake: toaster: don't re-create Target objects" brian avery
2015-09-29 4:45 ` [PATCH 22/22] toaster: orm remove the complicated querying on the ORM brian avery
2015-09-29 9:50 ` [PATCH v2 " Michael Wood
2015-09-29 9:54 ` Michael Wood [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=560A5FC4.7050304@intel.com \
--to=michael.g.wood@intel.com \
--cc=bitbake-devel@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.