Skip to content

Commit

Permalink
Do some more prefetching (good for large installs)
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed Oct 13, 2015
1 parent 5cf89a7 commit fb66085
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def getBUmachines(theid):
if machine_groups.count() != 0:
machines_unsorted = machine_groups[0].machine_set.all()
for machine_group in machine_groups[1:]:
machines_unsorted = machines_unsorted | machine_group.machine_set.all()
machines_unsorted = machines_unsorted | machine_group.machine_set.all().prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')
else:
machines_unsorted = None
machines=machines_unsorted
Expand Down
18 changes: 9 additions & 9 deletions server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ def index(request):
break

if user_level == 'GA':
machines = Machine.objects.all().prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates')
machines = Machine.objects.all().prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')
else:
machines = Machine.objects.none()
for business_unit in user.businessunit_set.all():
for group in business_unit.machinegroup_set.all():
machines = machines | group.machine_set.all()
machines = machines | group.machine_set.all().prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')

# Load in the default plugins if needed
utils.loadDefaultPlugins()
Expand Down Expand Up @@ -295,12 +295,12 @@ def machine_list(request, pluginName, data, page='front', theID=None):
if page == 'front':
# get all machines
if user.userprofile.level == 'GA':
machines = Machine.objects.all()
machines = Machine.objects.all().prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')
else:
machines = Machine.objects.none()
for business_unit in user.businessunit_set.all():
for group in business_unit.machinegroup_set.all():
machines = machines | group.machine_set.all()
machines = machines | group.machine_set.all().prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')
if page == 'bu_dashboard':
# only get machines for that BU
# Need to make sure the user is allowed to see this
Expand All @@ -319,7 +319,7 @@ def machine_list(request, pluginName, data, page='front', theID=None):
# only get machines from that group
machine_group = get_object_or_404(MachineGroup, pk=theID)
# check that the user has access to this
machines = Machine.objects.filter(machine_group=machine_group)
machines = Machine.objects.filter(machine_group=machine_group).prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')
# send the machines and the data to the plugin
for plugin in manager.getAllPlugins():
if plugin.name == pluginName:
Expand All @@ -342,12 +342,12 @@ def export_csv(request, pluginName, data, page='front', theID=None):
if page == 'front':
# get all machines
if user.userprofile.level == 'GA':
machines = Machine.objects.all()
machines = Machine.objects.all().prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')
else:
machines = Machine.objects.none()
for business_unit in user.businessunit_set.all():
for group in business_unit.machinegroup_set.all():
machines = machines | group.machine_set.all()
machines = machines | group.machine_set.all().prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')
if page == 'bu_dashboard':
# only get machines for that BU
# Need to make sure the user is allowed to see this
Expand All @@ -357,7 +357,7 @@ def export_csv(request, pluginName, data, page='front', theID=None):
if machine_groups.count() != 0:
machines_unsorted = machine_groups[0].machine_set.all()
for machine_group in machine_groups[1:]:
machines_unsorted = machines_unsorted | machine_group.machine_set.all()
machines_unsorted = machines_unsorted | machine_group.machine_set.all().prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')
else:
machines_unsorted = None
machines=machines_unsorted
Expand All @@ -366,7 +366,7 @@ def export_csv(request, pluginName, data, page='front', theID=None):
# only get machines from that group
machine_group = get_object_or_404(MachineGroup, pk=theID)
# check that the user has access to this
machines = Machine.objects.filter(machine_group=machine_group)
machines = Machine.objects.filter(machine_group=machine_group).prefetch_related('facts').prefetch_related('conditions').prefetch_related('pending_updates').prefetch_related('pending_apple_updates').prefetch_related('osquery_results')
# send the machines and the data to the plugin
for plugin in manager.getAllPlugins():
if plugin.name == pluginName:
Expand Down

0 comments on commit fb66085

Please sign in to comment.