[ENG-9596] Server slowdown when adding many contributors#11420
Open
antkryt wants to merge 3 commits intoCenterForOpenScience:feature/pbs-26-2from
Open
[ENG-9596] Server slowdown when adding many contributors#11420antkryt wants to merge 3 commits intoCenterForOpenScience:feature/pbs-26-2from
antkryt wants to merge 3 commits intoCenterForOpenScience:feature/pbs-26-2from
Conversation
8622ab5 to
996bba3
Compare
api/nodes/serializers.py
Outdated
Comment on lines
1279
to
1300
| uid = item.get('_id') | ||
| user = user_map.get(uid) | ||
| email = item.get('user', {}).get('email', None) | ||
| full_name = item.get('full_name') or (user.fullname if user and not user.is_registered else None) | ||
| if not uid and not full_name: | ||
| raise exceptions.ValidationError(detail='A user ID or full name must be provided to add a contributor.') | ||
| child_payload.append({ | ||
| 'user_id': uid, | ||
| 'user': user, | ||
| 'email': email, | ||
| 'full_name': full_name, | ||
| 'send_email': send_email_default, | ||
| 'permissions': _perm(item), | ||
| 'bibliographic': item.get('bibliographic'), | ||
| 'index': item.get('_order') if '_order' in item else None, | ||
| }) | ||
| try: | ||
| child.add_contributors_registered_or_not(child_payload, auth=auth, save=True) | ||
| except ValidationError as e: | ||
| raise exceptions.ValidationError(detail=e.messages[0]) | ||
| except ValueError as e: | ||
| raise exceptions.NotFound(detail=e.args[0]) |
Contributor
There was a problem hiding this comment.
this part repeats above, so let's create a separate method for parsing data
Comment on lines
+1459
to
+1463
| # Use DRF list_serializer_class if it exists, otherwise use default JSONAPIListSerializer | ||
| meta = getattr(cls, 'Meta', None) | ||
| list_cls = getattr(meta, 'list_serializer_class', None) | ||
| if list_cls: | ||
| return list_cls(*args, **kwargs) |
Contributor
There was a problem hiding this comment.
And would be nice to have a few tests to check data parsing inside of NodeContributorsBulkCreateListSerializer as it has a lot of logic
Contributor
Author
There was a problem hiding this comment.
We already have TestNodeContributorBulkCreate, my changes are not supposed to change any logic
Collaborator
|
@antkryt Some merge conflicts. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
optimize batch create contributors
Changes
see ticket comment section
QA Notes
Documentation
Side Effects
Ticket
https://openscience.atlassian.net/browse/ENG-9596