From: Stephen Finucane Date: Wed, 13 Jul 2016 09:57:29 +0000 (+0100) Subject: xmlrpc: Don't load all Patches into memory X-Git-Tag: v2.0.0-rc1~296 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b70ecf7d318cbf3c6badb9203adec873970b907;p=thirdparty%2Fpatchwork.git xmlrpc: Don't load all Patches into memory The way that reverse indexing of patches was implemented is broken. At present, it will retrieve all patches in memory and return the length from that data, then the slicing operation will then happen without querying the DB and slice the results cached from the len() evaluation. This is memory intensive, particularly for larger instances. Take advantage of Django's lazy loading to avoid this. Signed-off-by: Stephen Finucane Suggested-by: Damien Lespiau Reviewed-by: Andy Doan --- diff --git a/patchwork/views/xmlrpc.py b/patchwork/views/xmlrpc.py index 638b3b1a..8f759aac 100644 --- a/patchwork/views/xmlrpc.py +++ b/patchwork/views/xmlrpc.py @@ -406,8 +406,8 @@ def project_list(search_str=None, max_count=0): if max_count > 0: return list(map(project_to_dict, projects[:max_count])) elif max_count < 0: - return list(map(project_to_dict, - projects[len(projects) + max_count:])) + query = projects.reverse()[:-max_count] + return list(map(project_to_dict, reversed(query))) else: return list(map(project_to_dict, projects)) except Project.DoesNotExist: @@ -461,7 +461,8 @@ def person_list(search_str=None, max_count=0): if max_count > 0: return list(map(person_to_dict, people[:max_count])) elif max_count < 0: - return list(map(person_to_dict, people[len(people) + max_count:])) + query = people.reverse()[:-max_count] + return list(map(person_to_dict, reversed(query))) else: return list(map(person_to_dict, people)) except Person.DoesNotExist: @@ -606,8 +607,8 @@ def patch_list(filt=None): if max_count > 0: return list(map(patch_to_dict, patches[:max_count])) elif max_count < 0: - return list(map(patch_to_dict, - patches[len(patches) + max_count:])) + query = patches.reverse()[:-max_count] + return list(map(patch_to_dict, reversed(query))) else: return list(map(patch_to_dict, patches)) except Patch.DoesNotExist: @@ -802,7 +803,8 @@ def state_list(search_str=None, max_count=0): if max_count > 0: return list(map(state_to_dict, states[:max_count])) elif max_count < 0: - return list(map(state_to_dict, states[len(states) + max_count:])) + query = states.reverse()[:-max_count] + return list(map(state_to_dict, reversed(query))) else: return list(map(state_to_dict, states)) except State.DoesNotExist: