diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2015-06-08 12:26:12 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-06-12 00:01:48 +0100 |
commit | 88dca45a703867581084d15368b7c68117b3184c (patch) | |
tree | 243ac384041099289f89c669e712b64aacba2506 /bitbake | |
parent | 7c2b86625b75f0c3c5447d240175558be1e37919 (diff) | |
download | poky-88dca45a703867581084d15368b7c68117b3184c.tar.gz |
bitbake: toaster: eliminate duplicate querysets
The Layer_Version.get_equivalents_wpriority performs the same
function as Project.compatible_layerversions, but in memory and
with worse performance.
Replace the code in get_equivalents_wpriority with a call to
the project compatible_layerversions, which also returns a queryset
instead of a list (can be used to further enhance queries)
(Bitbake rev: fb5eb1d7759222573565936a964d602c148df139)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 41 |
1 files changed, 3 insertions, 38 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 198c6f5d22..8e73ee1afd 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -20,7 +20,7 @@ | |||
20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21 | 21 | ||
22 | from django.db import models | 22 | from django.db import models |
23 | from django.db.models import F, Q | 23 | from django.db.models import F, Q, Avg |
24 | from django.utils import timezone | 24 | from django.utils import timezone |
25 | 25 | ||
26 | 26 | ||
@@ -180,7 +180,7 @@ class Project(models.Model): | |||
180 | queryset = queryset.filter(layer__name = layer_name) | 180 | queryset = queryset.filter(layer__name = layer_name) |
181 | 181 | ||
182 | # order by layer version priority | 182 | # order by layer version priority |
183 | queryset = queryset.filter(layer_source__releaselayersourcepriority__release = release).order_by("-layer_source__releaselayersourcepriority__priority") | 183 | queryset = queryset.filter(Q(layer_source=None) | Q(layer_source__releaselayersourcepriority__release = release)).select_related('layer_source', 'layer', 'up_branch').annotate(prio=Avg("layer_source__releaselayersourcepriority__priority")).order_by("-prio") |
184 | 184 | ||
185 | return queryset | 185 | return queryset |
186 | 186 | ||
@@ -1062,42 +1062,7 @@ class Layer_Version(models.Model): | |||
1062 | return self._handle_url_path(self.layer.vcs_web_tree_base_url, '') | 1062 | return self._handle_url_path(self.layer.vcs_web_tree_base_url, '') |
1063 | 1063 | ||
1064 | def get_equivalents_wpriority(self, project): | 1064 | def get_equivalents_wpriority(self, project): |
1065 | """ Returns an ordered layerversion list that satisfies a LayerVersionDependency using the layer name and the current Project Releases' LayerSource priority """ | 1065 | return project.compatible_layerversions(layer_name = self.layer.name) |
1066 | |||
1067 | # layers created for this project, or coming from a build inthe project | ||
1068 | query = Q(project = project) | Q(build__project = project) | ||
1069 | if self.up_branch is not None: | ||
1070 | # the same up_branch name | ||
1071 | query |= Q(up_branch__name=self.up_branch.name) | ||
1072 | else: | ||
1073 | # or we have a layer in the project that's similar to mine (See the layer.name constraint below) | ||
1074 | query |= Q(projectlayer__project=project) | ||
1075 | |||
1076 | candidate_layer_versions = list(Layer_Version.objects.filter(layer__name = self.layer.name).filter(query).select_related('layer_source', 'layer', 'up_branch').order_by("-id")) | ||
1077 | |||
1078 | # optimization - if we have only one, we don't need no stinking sort | ||
1079 | if len(candidate_layer_versions) == 1: | ||
1080 | return candidate_layer_versions | ||
1081 | |||
1082 | # raise Exception(candidate_layer_versions) | ||
1083 | |||
1084 | release_priorities = {} | ||
1085 | |||
1086 | for ls_id, prio in map(lambda x: (x.layer_source_id, x.priority), project.release.releaselayersourcepriority_set.all().order_by("-priority")): | ||
1087 | release_priorities[ls_id] = prio | ||
1088 | |||
1089 | def _get_ls_priority(ls): | ||
1090 | # if there is no layer source, we have minus infinite priority, as we don't want this layer selected | ||
1091 | if ls == None: | ||
1092 | return -10000 | ||
1093 | try: | ||
1094 | return release_priorities[ls.id] | ||
1095 | except IndexError: | ||
1096 | raise Exception("Unknown %d %s" % (ls.id, release_priorities)) | ||
1097 | |||
1098 | return sorted( candidate_layer_versions , | ||
1099 | key = lambda x: _get_ls_priority(x.layer_source), | ||
1100 | reverse = True) | ||
1101 | 1066 | ||
1102 | def get_vcs_reference(self): | 1067 | def get_vcs_reference(self): |
1103 | if self.commit is not None and len(self.commit) > 0: | 1068 | if self.commit is not None and len(self.commit) > 0: |