Skip to content

Commit

Permalink
* One more speed tweak -- using AssetSummaryResource instead of the f…
Browse files Browse the repository at this point in the history
…ull resource. This allows only the specific sherdnotes to be sent down along with the associated parent asset info.

* Integrating suggested speed improvements. Thanks Filip!
  • Loading branch information
sdreher committed Sep 24, 2013
1 parent 742697f commit 4cf256e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mediathread/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def dehydrate(self, bundle):

# TODO: Also model-specific and leaky. Relies on there being a
# ``Manager`` there.
for m2m in the_m2ms.all():
for m2m in the_m2ms.select_related():
m2m_resource = self.get_related_resource(m2m)
m2m_bundle = Bundle(obj=m2m, request=bundle.request)
self.m2m_resources.append(m2m_resource)
Expand Down
2 changes: 1 addition & 1 deletion mediathread/assetmgr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(self,
blank=True, null=True, full=True)

class Meta:
queryset = Asset.objects.all().order_by('id')
queryset = Asset.objects.select_related('author').order_by('id')
excludes = ['added', 'modified', 'course', 'active', 'metadata_blob']
list_allowed_methods = ['get']
detail_allowed_methods = ['get']
Expand Down
4 changes: 2 additions & 2 deletions mediathread/djangosherd/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def apply_limits(self, request, object_list, exclude_global=True):
# Make sure the requesting user is allowed to see this note
invisible = []
courses = {}
for note in object_list.all():
for note in object_list.select_related('asset__course'):
course = note.asset.course

# Cache this out per course/user. It's just too slow otherwise
Expand Down Expand Up @@ -59,7 +59,7 @@ class SherdNoteResource(ModelResource):
full=True, null=True, blank=True)

class Meta:
queryset = SherdNote.objects.all().order_by("id")
queryset = SherdNote.objects.select_related('asset').order_by("id")
excludes = ['tags', 'body', 'added', 'modified']
list_allowed_methods = ['get']
detail_allowed_methods = ['get']
Expand Down
8 changes: 6 additions & 2 deletions mediathread/projects/lib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from courseaffils.lib import get_public_name
from mediathread.assetmgr.api import AssetResource
from mediathread.assetmgr.api import AssetSummaryResource
from mediathread.djangosherd.api import SherdNoteResource
from mediathread.projects.forms import ProjectForm
from random import choice
from string import letters
Expand Down Expand Up @@ -91,7 +92,8 @@ def composition_project_json(request, project, can_edit, version_number=None):
course = request.course if request.course \
else request.collaboration_context.content_object

asset_resource = AssetResource()
asset_resource = AssetSummaryResource()
sherd_resource = SherdNoteResource()
citations = project.citations()

data = {
Expand Down Expand Up @@ -120,6 +122,8 @@ def composition_project_json(request, project, can_edit, version_number=None):
},
'type': 'project',
'can_edit': can_edit,
'annotations': [sherd_resource.render_one(request, ann, rand)
for ann in citations],
}

assets = {}
Expand Down
2 changes: 1 addition & 1 deletion mediathread/release_id.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
LAST_GIT_HEAD = "7a617e76637edb8277eb2ae39f1238fff61eb050"
LAST_GIT_HEAD = "742697f1cecfc8cabf3f25b67c53bb50e360fd72"

0 comments on commit 4cf256e

Please sign in to comment.