-
Notifications
You must be signed in to change notification settings - Fork 70
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
[fix] Avoid redundant SQL write query during CA/Cert creation generation #168
base: master
Are you sure you want to change the base?
[fix] Avoid redundant SQL write query during CA/Cert creation generation #168
Conversation
Sir @nemesifier, I would like to contribute to this organization, I believe I have made changes correctly as you have mentioned. I want to move forward in the next challenges that you assign me, I will do my best to tackle them by facing them. Could you guide me on what to do further to prove myself? |
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.
Thank you for your patience @SitaGanesh!
We've been busy completing some projects before Christmas and the End of the year and couldn't look into this yet.
Please see my comments below.
Please also ensure tests and QA checks pass locally, read the contributing guidelines for more info on QA checks and tests:
https://openwisp.io/docs/dev/developer/contributing.html
Thank you @nemesifier for the feedback, and I was awaiting your response I will review and try to modify the test to utilize Let me repeat what you said for clarification:
Thank you for pointing me to the contributing guidelines and the references for |
I believe your understanding is correct, take your time. Ping us in the dev chat when ready. Thanks. |
Hi sir @nemesifier, this is the PR #170 which solves the both cases. I hope I have created a successful PR with all the requirements ment for consideration. If there will be any modification in the code please let me know. I will alter that them. |
Co-authored-by: Federico Capoano <[email protected]>
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.
I have made the suggested changes by removing the generate
variable and simplifying the save
method as follows:
def save(self, *args, **kwargs): if not self.pk and not self.certificate and not self.private_key: if not self.serial_number: self.serial_number = self._generate_serial_number() self._generate() super().save(*args, **kwargs)
the test cases goes here:-
I have made the suggested changes by using assertNumQueries
as follows:
def test_new(self): with self.assertNumQueries(3): # 3 queries to be made cert = self._create_cert() self.assertNotEqual(cert.certificate, '') self.assertNotEqual(cert.private_key, '') x509 = cert.x509 self.assertEqual(x509.get_serial_number(), cert.serial_number) subject = x509.get_subject()
Checklist
Reference to Existing Issue
Closes #120.
Description of Changes
Modified a test to the test_new function in test_cert.py to measure the number of database queries before and after the optimization. Ensuring that there should be at least 1 less query.
Screenshot