Skip to content
Browse files

Change the simple image output mode to not use full image objects,

and instead use .values() to get the data directly, then spit it
out in a dict to have it consumed by the json serializer.
  • Loading branch information...
1 parent bb496cd commit dc03c4d52c44a84733ca394ddb0a00ec0a6a2855 @crschmidt crschmidt committed Jun 4, 2011
Showing with 17 additions and 5 deletions.
  1. +17 −5 imageryindex/django/oamcatalog/main/views.py
View
22 imageryindex/django/oamcatalog/main/views.py
@@ -132,11 +132,23 @@ def handle_update(request, image):
limit = min(int(request.GET.get("limit", 1000)), 10000)
start = int(request.GET.get("start", 0))
end = start + limit
- images = images.order_by("-id")
- data = {'images': [
- i.to_json(output=output) for i in images[start:end]
- ]
- }
+ images = images.order_by("-id")
+
+ # Instantiating full image objects for thousands of images is slow;
+ # instead, just use .values and make our own dict here. Adding more
+ # properties here should be done with consideration.
+ if output == 'simple':
+ data = {'images':
+ [dict(x) for x in images[start:end].values("id", "width", "height", "url", "bbox")]
+ }
+ for i in data['images']:
+ i['bbox'] = list(i['bbox'].extent)
+
+ else:
+ data = {'images': [
+ i.to_json(output=output) for i in images[start:end]
+ ]
+ }
return json_response(request, data)
def home(request):

0 comments on commit dc03c4d

Please sign in to comment.
Something went wrong with that request. Please try again.