Skip to content

Commit

Permalink
Addressed performance issue in ShareableResource APIs. Resolves #539.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngehlenborg committed Jun 26, 2015
1 parent f7a4af3 commit 94150bf
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions refinery/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import uuid
import settings
from sets import Set
from django.conf.urls.defaults import url
from django.contrib.auth.models import User, Group
from guardian.shortcuts import get_objects_for_user, get_objects_for_group
Expand Down Expand Up @@ -116,15 +117,22 @@ def build_res_list(self, user):

# Turns on certain things depending on flags
def transform_res_list(self, user, res_list, request, **kwargs):
for i in res_list:
is_owner = user.has_perm(
'core.share_%s' % self.res_type._meta.verbose_name,
i
)

setattr(i, 'public', i.is_public())
setattr(i, 'is_owner', is_owner)

owned_res_set = Set(

This comment has been minimized.

Copy link
@ngehlenborg

ngehlenborg Jun 30, 2015

Author Contributor

Get list of owned resource ids.

get_objects_for_user(
user,
'core.share_%s' % self.res_type._meta.verbose_name).values_list( "id", flat=True))
public_res_set = Set(
get_objects_for_group(
ExtendedGroup.objects.public_group(),
'core.read_%s' % self.res_type._meta.verbose_name).values_list( "id", flat=True))

# instantiate owner and public fields
for res in res_list:
setattr(res, 'is_owner', res.id in owned_res_set )
setattr(res, 'public', res.id in public_res_set )

for i in res_list:
if 'sharing' in kwargs and kwargs['sharing']:
setattr(i, 'share_list', self.get_share_list(user, i))

Expand Down

1 comment on commit 94150bf

@AntonXue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a smart approach! :)

Please sign in to comment.