Skip to content
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

fixed false assumption that a participant (source) has only one surve… #637

Merged
merged 4 commits into from
Feb 6, 2017

Conversation

sjanssen2
Copy link
Contributor

…y_id, when deleting this participant.
See issue #636

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 63.707% when pulling 2974e15 on sjanssen2:bugfix_deleteSource into f7f42ea on biocore:master.

@sjanssen2
Copy link
Contributor Author

@EmbrietteH @wasade @josenavas please have a look at this PR which should fix the issue #636

@sjanssen2
Copy link
Contributor Author

sjanssen2 commented Feb 3, 2017

Please think about fact that a participant might have multiple email addresses. If so, do we want to list them only once in the ag.consent_revoked table or multiple times each with a different email?

Currently, the later is implemented.

Copy link
Member

@josenavas josenavas left a comment

Choose a reason for hiding this comment

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

Thanks @sjanssen2

It is possible to add a test with the current data in the DB?


sql = "DELETE FROM survey_answers WHERE survey_id = %s"
TRN.add(sql, [survey_id])
for survey_id in survey_ids:
Copy link
Member

Choose a reason for hiding this comment

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

Change to:

sql = "DELETE FROM survey_answers WHERE survey_id IN %s"
TRN.add(sql, [tuple(survey_ids)])

Note the call to tuple is required. This way all the delete is done in a single SQL query.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the tuple style. And will change the code to it.
A question for understanding: I thought that all SQL statements of this function are executed as a transaction, so why do I have to explicitly care here to trigger only one SQL query?

Copy link
Member

Choose a reason for hiding this comment

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

Even it is a single transaction the number of sql queries changes and each sql queries has some overhead. Reducing the number of SQL queries reduces the running time of the method.

Copy link
Member

Choose a reason for hiding this comment

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

Aaand clearly I need more coffee after reading my english on my last comment 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood :-) It's no issue of concurrence, but performance. Good to know.


sql = "DELETE FROM survey_answers_other WHERE survey_id = %s"
TRN.add(sql, [survey_id])
for survey_id in survey_ids:
Copy link
Member

Choose a reason for hiding this comment

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

Same as my previous comments - modify to use a single SQL query.


# Reset survey attached to barcode(s)
for info in self.getParticipantSamples(ag_login_id,
participant_name):
self.deleteSample(info['barcode'], ag_login_id)

sql = "DELETE FROM promoted_survey_ids WHERE survey_id = %s"
TRN.add(sql, [survey_id])
for survey_id in survey_ids:
Copy link
Member

Choose a reason for hiding this comment

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

Same here and in the next 3 for loops.

@@ -333,7 +344,9 @@ def deleteAGParticipantSurvey(self, ag_login_id, participant_name):
sql = """INSERT INTO ag.consent_revoked
(ag_login_id,participant_name, participant_email)
VALUES (%s, %s, %s)"""
TRN.add(sql, [ag_login_id, participant_name, participant_email])
for participant_email in list(participant_emails):
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the call to list is needed (you can iterate over a set). However, this can be changed to:

sql_args = [[ag_login_id, participant_name, pemail] for pemail in participant_emails]
TRN.add(sql, sql_args, many=True)

And add at the end of the function:

TRN.execute()

So we make sure that whatever is listed here is actually executed before returning this functions (but not necessarily committed)

@sjanssen2
Copy link
Contributor Author

test are not possible, because there is no (survey_login_id, participant_name) tuple that appears more than once :-(

@wasade
Copy link
Member

wasade commented Feb 6, 2017

👍 following @josenavas's comments

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 63.641% when pulling d6c820f on sjanssen2:bugfix_deleteSource into f7f42ea on biocore:master.

@qiyunzhu
Copy link

qiyunzhu commented Feb 6, 2017

I sat with @sjanssen2 and read the PR. It looks all good to the best of my knowledge.

@josenavas josenavas merged commit 14766a7 into biocore:master Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants