This changes the SelectPackagesTable to use the ProjectPackage table
instead of very large expensive queries to retrieve a list of currently
available packages for the project.

Signed-off-by: Michael Wood <[email protected]>
---
 bitbake/lib/toaster/toastergui/tables.py | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/bitbake/lib/toaster/toastergui/tables.py 
b/bitbake/lib/toaster/toastergui/tables.py
index 8147c1b..9476887 100644
--- a/bitbake/lib/toaster/toastergui/tables.py
+++ b/bitbake/lib/toaster/toastergui/tables.py
@@ -22,6 +22,7 @@
 from toastergui.widgets import ToasterTable
 from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
 from orm.models import CustomImageRecipe, Package, Target, Build
+from orm.models import ProjectPackage
 from django.db.models import Q, Max, Sum
 from django.conf.urls import url
 from django.core.urlresolvers import reverse
@@ -677,7 +678,7 @@ class PackagesTable(ToasterTable):
 
 
 class SelectPackagesTable(PackagesTable):
-    """ Table to display the packages to add and remove from an image """
+    """ Table to display packages to add and remove from a custom recipe"""
 
     def __init__(self, *args, **kwargs):
         super(SelectPackagesTable, self).__init__(*args, **kwargs)
@@ -687,15 +688,20 @@ class SelectPackagesTable(PackagesTable):
         cust_recipe = CustomImageRecipe.objects.get(pk=kwargs['recipeid'])
         prj = Project.objects.get(pk = kwargs['pid'])
 
-        current_packages = cust_recipe.packages.all()
+        current_packages = self.cust_recipe.get_all_packages()
 
-        # Get all the packages that are in the custom image
-        # Get all the packages built by builds in the current project
-        # but not those ones that are already in the custom image
-        self.queryset = Package.objects.filter(
-                            Q(pk__in=current_packages) |
-                            (Q(build__project=prj) &
-                            ~Q(name__in=current_packages.values_list('name'))))
+        current_recipes = prj.get_available_recipes()
+
+        # Exclude ghost packages and ones which have locale in the name
+        # This is a work around locale packages being dynamically created
+        # and therefore not recognised as packages by bitbake.
+        # We also only show packages which recipes->layers are in the project
+        self.queryset = ProjectPackage.objects.filter(
+                Q(project=prj) &
+                ~Q(recipe=None) &
+                Q(recipe__in=current_recipes) &
+                ~Q(name__icontains="locale") &
+                ~Q(name__icontains="packagegroup"))
 
         self.queryset = self.queryset.order_by('name')
 
@@ -708,7 +714,8 @@ class SelectPackagesTable(PackagesTable):
         custom_recipe = CustomImageRecipe.objects.get(pk=kwargs['recipe_id'])
 
         context['recipe'] = custom_recipe
-        context['approx_pkg_size'] =  
custom_recipe.package_set.aggregate(Sum('size'))
+        context['approx_pkg_size'] = \
+                        custom_recipe.get_all_packages().aggregate(Sum('size'))
         return context
 
 
-- 
2.1.4

-- 
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster

Reply via email to