diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2015-03-10 17:38:00 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-03-16 17:44:09 +0000 |
commit | 193989cec807120307cda50c616118dca4025b8a (patch) | |
tree | 4e63be374877262cbc2e6d985454b677e3acd31b | |
parent | 2b629e618227632bc8b774796d760904fcca92f4 (diff) | |
download | poky-193989cec807120307cda50c616118dca4025b8a.tar.gz |
bitbake: toastergui: tables display optimizations
This patch brings in a new set of optimizations in the tables pages,
with the focus of reducing the number of SQL queries performed per
row.
(Bitbake rev: a1ad86febb9d8a4ee7f15aa726f267d64b8e0dc4)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 40 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/templates/targets.html | 2 | ||||
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 14 |
3 files changed, 33 insertions, 23 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index b941d4ab20..2132f8799c 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -182,7 +182,7 @@ class Project(models.Model): | |||
182 | 182 | ||
183 | # returns a set of layer-equivalent set of layers already in project | 183 | # returns a set of layer-equivalent set of layers already in project |
184 | def projectlayer_equivalent_set(self): | 184 | def projectlayer_equivalent_set(self): |
185 | return [j for i in [x.layercommit.get_equivalents_wpriority(self) for x in self.projectlayer_set.all()] for j in i] | 185 | return [j for i in [x.layercommit.get_equivalents_wpriority(self) for x in self.projectlayer_set.all().select_related("up_branch")] for j in i] |
186 | 186 | ||
187 | def schedule_build(self): | 187 | def schedule_build(self): |
188 | from bldcontrol.models import BuildRequest, BRTarget, BRLayer, BRVariable, BRBitbake | 188 | from bldcontrol.models import BuildRequest, BRTarget, BRLayer, BRVariable, BRBitbake |
@@ -545,11 +545,6 @@ class Recipe(models.Model): | |||
545 | bugtracker = models.URLField(blank=True) | 545 | bugtracker = models.URLField(blank=True) |
546 | file_path = models.FilePathField(max_length=255) | 546 | file_path = models.FilePathField(max_length=255) |
547 | 547 | ||
548 | def get_vcs_link_url(self): | ||
549 | if self.layer_version.layer.vcs_web_file_base_url is None: | ||
550 | return "" | ||
551 | return self.layer_version.layer.vcs_web_file_base_url.replace('%path%', self.file_path).replace('%branch%', self.layer_version.up_branch.name) | ||
552 | |||
553 | def get_layersource_view_url(self): | 548 | def get_layersource_view_url(self): |
554 | if self.layer_source is None: | 549 | if self.layer_source is None: |
555 | return "" | 550 | return "" |
@@ -708,8 +703,6 @@ class LayerIndexLayerSource(LayerSource): | |||
708 | self.sourcetype = LayerSource.TYPE_LAYERINDEX | 703 | self.sourcetype = LayerSource.TYPE_LAYERINDEX |
709 | 704 | ||
710 | def get_object_view(self, branch, objectype, upid): | 705 | def get_object_view(self, branch, objectype, upid): |
711 | if self != branch.layer_source: | ||
712 | raise Exception("Invalid branch specification") | ||
713 | return self.apiurl + "../branch/" + branch.name + "/" + objectype + "/?q=" + str(upid) | 706 | return self.apiurl + "../branch/" + branch.name + "/" + objectype + "/?q=" + str(upid) |
714 | 707 | ||
715 | def update(self): | 708 | def update(self): |
@@ -1044,14 +1037,6 @@ class Layer_Version(models.Model): | |||
1044 | 1037 | ||
1045 | def get_equivalents_wpriority(self, project): | 1038 | def get_equivalents_wpriority(self, project): |
1046 | """ Returns an ordered layerversion list that satisfies a LayerVersionDependency using the layer name and the current Project Releases' LayerSource priority """ | 1039 | """ Returns an ordered layerversion list that satisfies a LayerVersionDependency using the layer name and the current Project Releases' LayerSource priority """ |
1047 | def _get_ls_priority(ls): | ||
1048 | try: | ||
1049 | # if there is no layer source, we have minus infinite priority, as we don't want this layer selected | ||
1050 | if ls == None: | ||
1051 | return -10000 | ||
1052 | return ls.releaselayersourcepriority_set.get(release=project.release).priority | ||
1053 | except ReleaseLayerSourcePriority.DoesNotExist: | ||
1054 | raise | ||
1055 | 1040 | ||
1056 | # layers created for this project, or coming from a build inthe project | 1041 | # layers created for this project, or coming from a build inthe project |
1057 | query = Q(project = project) | Q(build__project = project) | 1042 | query = Q(project = project) | Q(build__project = project) |
@@ -1062,8 +1047,27 @@ class Layer_Version(models.Model): | |||
1062 | # or we have a layer in the project that's similar to mine (See the layer.name constraint below) | 1047 | # or we have a layer in the project that's similar to mine (See the layer.name constraint below) |
1063 | query |= Q(projectlayer__project=project) | 1048 | query |= Q(projectlayer__project=project) |
1064 | 1049 | ||
1065 | return sorted( | 1050 | 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")) |
1066 | Layer_Version.objects.filter(layer__name = self.layer.name).filter(query).select_related('layer_source', 'layer').order_by("-id"), | 1051 | |
1052 | # optimization - if we have only one, we don't need no stinking sort | ||
1053 | if len(candidate_layer_versions) == 1: | ||
1054 | return candidate_layer_versions | ||
1055 | |||
1056 | # raise Exception(candidate_layer_versions) | ||
1057 | |||
1058 | release_priorities = map(lambda x: (x.layer_source_id, x.priority), project.release.releaselayersourcepriority_set.all().order_by("-priority")) | ||
1059 | |||
1060 | |||
1061 | def _get_ls_priority(ls): | ||
1062 | # if there is no layer source, we have minus infinite priority, as we don't want this layer selected | ||
1063 | if ls == None: | ||
1064 | return -10000 | ||
1065 | try: | ||
1066 | return release_priorities[ls.id] | ||
1067 | except IndexError: | ||
1068 | raise Exception("Unknown %d %s" % (ls.id, release_priorities)) | ||
1069 | |||
1070 | return sorted( candidate_layer_versions , | ||
1067 | key = lambda x: _get_ls_priority(x.layer_source), | 1071 | key = lambda x: _get_ls_priority(x.layer_source), |
1068 | reverse = True) | 1072 | reverse = True) |
1069 | 1073 | ||
diff --git a/bitbake/lib/toaster/toastergui/templates/targets.html b/bitbake/lib/toaster/toastergui/templates/targets.html index 690c6a5d36..f918d6cff2 100644 --- a/bitbake/lib/toaster/toastergui/templates/targets.html +++ b/bitbake/lib/toaster/toastergui/templates/targets.html | |||
@@ -60,7 +60,7 @@ | |||
60 | <td class="description">{% if o.description %}{{o.description}}{% else %}{{o.summary}}{%endif%}</td> | 60 | <td class="description">{% if o.description %}{{o.description}}{% else %}{{o.summary}}{%endif%}</td> |
61 | <td class="recipe-file"> | 61 | <td class="recipe-file"> |
62 | <code>{{o.file_path}}</code> | 62 | <code>{{o.file_path}}</code> |
63 | <a href="{{o.get_vcs_link_url}}{{o.file_path}}" target="_blank"><i class="icon-share get-info"></i></a> | 63 | <a href="{{o.vcs_link_url}}" target="_blank"><i class="icon-share get-info"></i></a> |
64 | </td> | 64 | </td> |
65 | <td class="target-section">{{o.section}}</td> | 65 | <td class="target-section">{{o.section}}</td> |
66 | <td class="license">{{o.license}}</td> | 66 | <td class="license">{{o.license}}</td> |
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 90d47c640c..541b16ab1d 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
@@ -515,17 +515,19 @@ def target_common( request, build_id, target_id, variant ): | |||
515 | packages_sum = queryset.aggregate( Sum( 'installed_size' )) | 515 | packages_sum = queryset.aggregate( Sum( 'installed_size' )) |
516 | queryset = _get_queryset( | 516 | queryset = _get_queryset( |
517 | Package, queryset, filter_string, search_term, ordering_string, 'name' ) | 517 | Package, queryset, filter_string, search_term, ordering_string, 'name' ) |
518 | queryset = queryset.select_related("recipe", "recipe__layer_version", "recipe__layer_version__layer") | ||
518 | packages = _build_page_range( Paginator(queryset, pagesize), request.GET.get( 'page', 1 )) | 519 | packages = _build_page_range( Paginator(queryset, pagesize), request.GET.get( 'page', 1 )) |
519 | 520 | ||
520 | 521 | ||
522 | |||
521 | build = Build.objects.get( pk = build_id ) | 523 | build = Build.objects.get( pk = build_id ) |
522 | 524 | ||
523 | # bring in package dependencies | 525 | # bring in package dependencies |
524 | for p in packages.object_list: | 526 | for p in packages.object_list: |
525 | p.runtime_dependencies = p.package_dependencies_source.filter( | 527 | p.runtime_dependencies = p.package_dependencies_source.filter( |
526 | target_id = target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS ) | 528 | target_id = target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS ).select_related("depends_on") |
527 | p.reverse_runtime_dependencies = p.package_dependencies_target.filter( | 529 | p.reverse_runtime_dependencies = p.package_dependencies_target.filter( |
528 | target_id = target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS ) | 530 | target_id = target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS ).select_related("package") |
529 | tc_package = { | 531 | tc_package = { |
530 | 'name' : 'Package', | 532 | 'name' : 'Package', |
531 | 'qhelp' : 'Packaged output resulting from building a recipe included in this image', | 533 | 'qhelp' : 'Packaged output resulting from building a recipe included in this image', |
@@ -2755,7 +2757,7 @@ if toastermain.settings.MANAGED: | |||
2755 | # get unique values for 'name', and select the maximum ID for each entry (the max id is the newest one) | 2757 | # get unique values for 'name', and select the maximum ID for each entry (the max id is the newest one) |
2756 | queryset_with_search_maxids = queryset_with_search.values('name').distinct().annotate(max_id=Max('id')).values_list('max_id') | 2758 | queryset_with_search_maxids = queryset_with_search.values('name').distinct().annotate(max_id=Max('id')).values_list('max_id') |
2757 | 2759 | ||
2758 | queryset_with_search = queryset_with_search.filter(id__in=queryset_with_search_maxids).select_related('layer_version', 'layer_version__layer', 'layer_version__up_branch') | 2760 | queryset_with_search = queryset_with_search.filter(id__in=queryset_with_search_maxids).select_related('layer_version', 'layer_version__layer', 'layer_version__up_branch', 'layer_source') |
2759 | 2761 | ||
2760 | 2762 | ||
2761 | # retrieve the objects that will be displayed in the table; targets a paginator and gets a page range to display | 2763 | # retrieve the objects that will be displayed in the table; targets a paginator and gets a page range to display |
@@ -2763,7 +2765,11 @@ if toastermain.settings.MANAGED: | |||
2763 | 2765 | ||
2764 | for e in target_info.object_list: | 2766 | for e in target_info.object_list: |
2765 | e.preffered_layerversion = e.layer_version.get_equivalents_wpriority(prj)[0] | 2767 | e.preffered_layerversion = e.layer_version.get_equivalents_wpriority(prj)[0] |
2766 | 2768 | e.vcs_link_url = Layer.objects.filter(name = e.preffered_layerversion.layer.name).exclude(vcs_web_file_base_url__isnull=True)[0].vcs_web_file_base_url | |
2769 | if e.vcs_link_url != None: | ||
2770 | fp = e.preffered_layerversion.dirpath + "/" + e.file_path | ||
2771 | e.vcs_link_url = e.vcs_link_url.replace('%path%', fp) | ||
2772 | e.vcs_link_url = e.vcs_link_url.replace('%branch%', e.preffered_layerversion.up_branch.name) | ||
2767 | 2773 | ||
2768 | context = { | 2774 | context = { |
2769 | 'projectlayerset' : jsonfilter(map(lambda x: x.layercommit.id, prj.projectlayer_set.all().select_related("layercommit"))), | 2775 | 'projectlayerset' : jsonfilter(map(lambda x: x.layercommit.id, prj.projectlayer_set.all().select_related("layercommit"))), |