Repository navigation
brands: in memory cache #26926
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
brands: in memory cache #26926
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
046714c
brands: in memory cache
BeryJu f090841
Merge branch 'main' into brands/in-memory-cache
BeryJu ee975d6
fix tests
BeryJu e0b27bb
same cache for system settings
BeryJu 073e248
fix typing
BeryJu 6186875
invalidate all via channels
BeryJu 5139868
Merge branch 'main' into brands/in-memory-cache
BeryJu 60435be
Merge branch 'main' into brands/in-memory-cache
BeryJu 699e9a7
Revert "invalidate all via channels"
BeryJu ecb68cc
fixup
BeryJu 2131682
Merge branch 'main' into brands/in-memory-cache
BeryJu 59ab7fa
Merge branch 'main' into brands/in-memory-cache
BeryJu efbaaed
Merge branch 'main' into brands/in-memory-cache
BeryJu 80cf033
Merge branch 'main' into brands/in-memory-cache
BeryJu 75b0bdf
down to 1 min, add to API
BeryJu 1ddaa67
add ui
BeryJu 2e06cb6
fix gen
BeryJu f9236e9
Apply suggestion from @BeryJu
BeryJu f3b27c5
fixes for web-e2e
BeryJu 02b1dd3
Merge branch 'main' into brands/in-memory-cache
BeryJu 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
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,20 @@ | ||
| from django.http import HttpRequest, HttpResponse | ||
| from django.test import RequestFactory, TestCase | ||
| from django.test import TestCase | ||
|
|
||
| from authentik.admin.middleware import SystemSettingsMiddleware | ||
| from authentik.admin.models import SystemSettings | ||
| from authentik.admin.utils import get_system_settings | ||
|
|
||
|
|
||
| class TestSystemSettingsCache(TestCase): | ||
| def test_scoped_to_request(self): | ||
| """Settings are only cached within a single request""" | ||
| seen = [] | ||
| def test_cached(self): | ||
| """Settings are cached across calls""" | ||
| self.assertIs(get_system_settings(), get_system_settings()) | ||
|
|
||
| def view(request: HttpRequest) -> HttpResponse: | ||
| seen.extend([get_system_settings(), get_system_settings()]) | ||
| return HttpResponse() | ||
|
|
||
| middleware = SystemSettingsMiddleware(view) | ||
| middleware(RequestFactory().get("/")) | ||
| middleware(RequestFactory().get("/")) | ||
| self.assertIs(seen[0], seen[1]) | ||
| self.assertIsNot(seen[1], seen[2]) | ||
| self.assertIs(seen[2], seen[3]) | ||
| self.assertIsNot(get_system_settings(), get_system_settings()) | ||
|
|
||
| def test_fresh_outside_requests(self): | ||
| """System settings cache is not used outside of a request""" | ||
| def test_cleared_on_save(self): | ||
| """Saving the settings drops the cached instance""" | ||
| first = get_system_settings() | ||
| SystemSettings.objects.filter(pk=True).update(avatars="none") | ||
| settings = SystemSettings.objects.get(pk=True) | ||
| settings.avatars = "none" | ||
| settings.save() | ||
| second = get_system_settings() | ||
| self.assertIsNot(first, second) | ||
| self.assertEqual(second.avatars, "none") |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """authentik brand signals""" | ||
|
|
||
| from django.db.models.signals import post_delete, post_save | ||
| from django.dispatch import receiver | ||
|
|
||
| from authentik.brands.models import Brand | ||
| from authentik.brands.utils import get_brand_for_request | ||
| from authentik.core.models import Application | ||
| from authentik.flows.models import Flow | ||
|
|
||
|
|
||
| @receiver(post_save, sender=Brand) | ||
| @receiver(post_delete, sender=Brand) | ||
| # Cached brands carry their flows and default application (see _BRAND_RELATED_FK_FIELDS) | ||
| @receiver(post_save, sender=Flow) | ||
| @receiver(post_delete, sender=Flow) | ||
| @receiver(post_save, sender=Application) | ||
| @receiver(post_delete, sender=Application) | ||
| def brand_cache_clear(**_): | ||
| """Drop cached brand lookups when a brand or an object it caches changes""" | ||
| get_brand_for_request.cache_clear() |
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.