diff options
author | AlanCoding <arominge@redhat.com> | 2017-06-25 02:13:31 +0200 |
---|---|---|
committer | AlanCoding <arominge@redhat.com> | 2017-06-25 02:13:31 +0200 |
commit | fc59a97e44f28173ad23ac76053598bb765878a8 (patch) | |
tree | e334acbac96bb1bf4df770b75e7f8438974c3b4e | |
parent | Merge pull request #6595 from jangsutsr/6234_set_priority_rules_for_find_matc... (diff) | |
download | awx-fc59a97e44f28173ad23ac76053598bb765878a8.tar.xz awx-fc59a97e44f28173ad23ac76053598bb765878a8.zip |
cache view parent obj & add prefetch to sublists
-rw-r--r-- | awx/api/generics.py | 6 | ||||
-rw-r--r-- | awx/api/views.py | 5 |
2 files changed, 10 insertions, 1 deletions
diff --git a/awx/api/generics.py b/awx/api/generics.py index 2345867e83..a6ec9b7939 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -368,12 +368,16 @@ class ListCreateAPIView(ListAPIView, generics.ListCreateAPIView): class ParentMixin(object): + parent_object = None def get_parent_object(self): + if self.parent_object is not None: + return self.parent_object parent_filter = { self.lookup_field: self.kwargs.get(self.lookup_field, None), } - return get_object_or_404(self.parent_model, **parent_filter) + self.parent_object = get_object_or_404(self.parent_model, **parent_filter) + return self.parent_object def check_parent_access(self, parent=None): parent = parent or self.get_parent_object() diff --git a/awx/api/views.py b/awx/api/views.py index a63f762297..ed6becca69 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -1968,6 +1968,7 @@ class InventoryHostsList(SubListCreateAttachDetachAPIView): parent_model = Inventory relationship = 'hosts' parent_key = 'inventory' + capabilities_prefetch = ['inventory.admin'] class HostGroupsList(ControlledByScmMixin, SubListCreateAttachDetachAPIView): @@ -2226,6 +2227,7 @@ class GroupHostsList(ControlledByScmMixin, SubListCreateAttachDetachAPIView): serializer_class = HostSerializer parent_model = Group relationship = 'hosts' + capabilities_prefetch = ['inventory.admin'] def update_raw_data(self, data): data.pop('inventory', None) @@ -2252,6 +2254,7 @@ class GroupAllHostsList(SubListAPIView): serializer_class = HostSerializer parent_model = Group relationship = 'hosts' + capabilities_prefetch = ['inventory.admin'] def get_queryset(self): parent = self.get_parent_object() @@ -2608,6 +2611,7 @@ class InventorySourceHostsList(SubListAPIView): parent_model = InventorySource relationship = 'hosts' new_in_148 = True + capabilities_prefetch = ['inventory.admin'] class InventorySourceGroupsList(SubListAPIView): @@ -3936,6 +3940,7 @@ class JobEventHostsList(SubListAPIView): parent_model = JobEvent relationship = 'hosts' view_name = _('Job Event Hosts List') + capabilities_prefetch = ['inventory.admin'] class BaseJobEventsList(SubListAPIView): |