-
-
Notifications
You must be signed in to change notification settings - Fork 298
[feature] Invalidate VPN cache when organization config variables change #1177
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
7e365af
30475e5
e77e6d3
cf5582b
6384a07
58e1527
87d7730
ed6beb7
35f82fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,3 +152,20 @@ def organization_disabled_handler(instance, **kwargs): | |
| # No change in is_active | ||
| return | ||
| tasks.invalidate_controller_views_cache.delay(str(instance.id)) | ||
|
|
||
|
|
||
| def organization_config_settings_change_handler(instance, **kwargs): | ||
| """ | ||
| Invalidates VPN cache when OrganizationConfigSettings context changes. | ||
| """ | ||
| if instance._state.adding: | ||
| return | ||
|
|
||
| try: | ||
| db_instance = instance.__class__.objects.only("context").get(id=instance.id) | ||
|
Member
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. we can avoid this extra query, we already have similar idioms to handle similar cases, see: https://github.com/search?q=repo%3Aopenwisp%2Fopenwisp-controller+self._initial&type=code This means that if you implement it this way, this receiver may be completely unnecessary. |
||
| if db_instance.context != instance.context: | ||
| transaction.on_commit( | ||
| lambda: tasks.invalidate_organization_vpn_cache.delay(str(instance.organization_id)) | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| except instance.__class__.DoesNotExist: | ||
| pass | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,20 +18,3 @@ def test_organization_disabled_handler(self, mocked_task): | |
| org.is_active = False | ||
| org.save() | ||
| mocked_task.assert_called_once() | ||
|
|
||
| mocked_task.reset_mock() | ||
| with self.subTest("Test task not executed on saving inactive org"): | ||
| org.name = "Changed named" | ||
| org.save() | ||
| mocked_task.assert_not_called() | ||
|
|
||
| with self.subTest("Test task not executed on creating inactive org"): | ||
| inactive_org = self._create_org( | ||
| is_active=False, name="inactive", slug="inactive" | ||
| ) | ||
| mocked_task.assert_not_called() | ||
|
|
||
| with self.subTest("Test task not executed on changing inactive to active org"): | ||
| inactive_org.is_active = True | ||
| inactive_org.save() | ||
| mocked_task.assert_not_called() | ||
|
Member
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. This doesn't look right. We don't want to trigger cache invalidation in these cases. |
||
Uh oh!
There was an error while loading. Please reload this page.