-
Notifications
You must be signed in to change notification settings - Fork 4.3k
loc mapper memoize #1954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
loc mapper memoize #1954
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f4beb8b
Reduce sql queries for groupname tests.
3bd76f9
Use mongo indices for all queries
3f420e3
loc_mapper memoize all translations
f6de4f2
Location map uses a separate cache and defaults to general
9ad7a1c
Document performance optimization and auth generality changes.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,7 @@ def get_all_course_role_groupnames(location, role, use_filter=True): | |
| # filter to the ones which exist | ||
| default = groupnames[0] | ||
| if use_filter: | ||
| groupnames = [group for group in groupnames if Group.objects.filter(name=group).exists()] | ||
| groupnames = [group.name for group in Group.objects.filter(name__in=groupnames)] | ||
| return groupnames, default | ||
|
|
||
|
|
||
|
|
@@ -203,12 +203,8 @@ def remove_user_from_course_group(caller, user, location, role): | |
|
|
||
| # see if the user is actually in that role, if not then we don't have to do anything | ||
| groupnames, _ = get_all_course_role_groupnames(location, role) | ||
| for groupname in groupnames: | ||
| groups = user.groups.filter(name=groupname) | ||
| if groups: | ||
| # will only be one with that name | ||
| user.groups.remove(groups[0]) | ||
| user.save() | ||
| user.groups.remove(*user.groups.filter(name__in=groupnames)) | ||
| user.save() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| def remove_user_from_creator_group(caller, user): | ||
|
|
@@ -243,7 +239,7 @@ def is_user_in_course_group_role(user, location, role, check_staff=True): | |
| if check_staff and user.is_staff: | ||
| return True | ||
| groupnames, _ = get_all_course_role_groupnames(location, role) | ||
| return any(user.groups.filter(name=groupname).exists() for groupname in groupnames) | ||
| return user.groups.filter(name__in=groupnames).exists() | ||
|
|
||
| return False | ||
|
|
||
|
|
@@ -266,7 +262,7 @@ def is_user_in_creator_group(user): | |
|
|
||
| # Feature flag for using the creator group setting. Will be removed once the feature is complete. | ||
| if settings.FEATURES.get('ENABLE_CREATOR_GROUP', False): | ||
| return user.groups.filter(name=COURSE_CREATOR_GROUP_NAME).count() > 0 | ||
| return user.groups.filter(name=COURSE_CREATOR_GROUP_NAME).exists() | ||
|
|
||
| return True | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |
|
|
||
| from django.test.utils import override_settings | ||
| from django.conf import settings | ||
| from django.core.urlresolvers import reverse | ||
| from path import path | ||
| from tempdir import mkdtemp_clean | ||
| from fs.osfs import OSFS | ||
|
|
@@ -427,7 +426,7 @@ def test_static_tab_deletion(self): | |
|
|
||
| course = module_store.get_item(course_location) | ||
| num_tabs = len(course.tabs) | ||
| last_tab = course.tabs[num_tabs - 1] | ||
| last_tab = course.tabs[-1] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pythonic last ele mechanism. Not important. |
||
| url_slug = last_tab['url_slug'] | ||
| delete_url = self._get_tab_locator(course, last_tab).url_reverse('xblock') | ||
|
|
||
|
|
@@ -446,7 +445,7 @@ def tab_matches(tab): | |
|
|
||
| def _get_tab_locator(self, course, tab): | ||
| """ Returns the locator for a given tab. """ | ||
| tab_location = 'i4x://MITx/999/static_tab/{0}'.format(tab['url_slug']) | ||
| tab_location = 'i4x://edX/999/static_tab/{0}'.format(tab['url_slug']) | ||
| return loc_mapper().translate_location( | ||
| course.location.course_id, Location(tab_location), False, True | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the syntax for name__in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
field__in = listvalues translates to a sql
where field in listvaluesSomething @cpennington pointed out to me and correctly suggested we use.