Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
26ed32a
add cache for IAM
eric-intuitem Dec 31, 2025
ade2e79
Update models.py
eric-intuitem Jan 1, 2026
71cf471
fix cache / improve perf
eric-intuitem Jan 1, 2026
0edee2c
fix cache bump for roles m2m
eric-intuitem Jan 1, 2026
8e14d74
cache root folder
eric-intuitem Jan 1, 2026
afd66b7
fix pg migration issue
eric-intuitem Jan 1, 2026
99a40b0
Update models.py
eric-intuitem Jan 1, 2026
b981b7d
Update models.py
eric-intuitem Jan 1, 2026
e528724
add cache ready flag
eric-intuitem Jan 1, 2026
4209961
try another strategy
eric-intuitem Jan 1, 2026
b5539c2
fix comment
eric-intuitem Jan 1, 2026
44c4e47
further cache optims
eric-intuitem Jan 1, 2026
03a11e8
Merge branch 'main' into folders_cache
eric-intuitem Jan 2, 2026
59d5b29
Merge branch 'main' into folders_cache
eric-intuitem Jan 2, 2026
48803e7
manage permissions
eric-intuitem Jan 3, 2026
ad8d6b9
simplify cache_builders.py
eric-intuitem Jan 3, 2026
94ed9db
improve type checking
eric-intuitem Jan 4, 2026
20cb0ae
mypy checks
eric-intuitem Jan 4, 2026
8b968e0
Update cache_builders.py
eric-intuitem Jan 4, 2026
5c83bbc
Update pyproject.toml
eric-intuitem Jan 4, 2026
d693330
Update poetry.lock
eric-intuitem Jan 4, 2026
2ff91dd
fix regression
eric-intuitem Jan 4, 2026
8857327
ruff
eric-intuitem Jan 4, 2026
762721f
Update models.py
eric-intuitem Jan 4, 2026
7a4115a
Merge branch 'main' into folders_cache
eric-intuitem Jan 4, 2026
4854e59
enforce is_recursive
eric-intuitem Jan 4, 2026
3c3d1b9
fix coderabbit comment
eric-intuitem Jan 4, 2026
1cd6a5f
remove useless code
eric-intuitem Jan 4, 2026
616a6bd
update comment
eric-intuitem Jan 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/ciso_assistant/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def set_ciso_assistant_url(_, __, event_dict):
},
"loggers": {
"": {"handlers": ["console"], "level": LOG_LEVEL},
# to trace all db calls, uncoment these lines
# "django.db.backends": {
# "handlers": ["console"],
# "level": "DEBUG",
# "propagate": False,
# },
},
}

Expand Down Expand Up @@ -224,6 +230,7 @@ def set_ciso_assistant_url(_, __, event_dict):
"core.custom_middleware.AuditlogMiddleware",
"allauth.account.middleware.AccountMiddleware",
]
# for DB performance measurements, uncoment the following line
# MIDDLEWARE += ["querycount.middleware.QueryCountMiddleware"]
ROOT_URLCONF = "ciso_assistant.urls"
# we leave these for the API UI tools - even if Django templates and Admin are not used anymore
Expand Down
9 changes: 8 additions & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ class BaseModelViewSet(viewsets.ModelViewSet):
ordering_fields = "__all__"
search_fields = ["name", "description"]
filterset_fields = []
model = None
model: type[models.Model] | None = None

serializers_module = "core.serializers"

Expand Down Expand Up @@ -656,6 +656,13 @@ def get_queryset(self) -> models.query.QuerySet:
)[0]

queryset = self.model.objects.filter(id__in=object_ids_view)

field_names = {f.name for f in self.model._meta.get_fields()}
if "parent_folder" in field_names:
queryset = queryset.select_related("parent_folder")
if "filtering_labels" in field_names:
queryset = queryset.prefetch_related("filtering_labels")

return queryset

def get_serializer_context(self):
Expand Down
46 changes: 46 additions & 0 deletions backend/iam/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,49 @@
class IamConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "iam"

def ready(self):
from django.apps import apps
from django.db.models.signals import m2m_changed

from iam.cache_builders import (
invalidate_groups_cache,
invalidate_assignments_cache,
invalidate_roles_cache,
)

User = apps.get_model("iam", "User")
RoleAssignment = apps.get_model("iam", "RoleAssignment")
Role = apps.get_model("iam", "Role")

def _user_groups_changed(sender, instance, action, **kwargs):
if action in {"post_add", "post_remove", "post_clear"}:
invalidate_groups_cache()
invalidate_assignments_cache()

def _ra_perimeters_changed(sender, instance, action, **kwargs):
if action in {"post_add", "post_remove", "post_clear"}:
invalidate_assignments_cache()

def _role_permissions_changed(sender, instance, action, **kwargs):
if action in {"post_add", "post_remove", "post_clear"}:
invalidate_roles_cache()

m2m_changed.connect(
_user_groups_changed,
sender=User.user_groups.through,
dispatch_uid="iam.user_groups.m2m.invalidate_caches",
weak=False,
)
m2m_changed.connect(
_ra_perimeters_changed,
sender=RoleAssignment.perimeter_folders.through,
dispatch_uid="iam.roleassignment.perimeter_folders.m2m.invalidate_assignments_cache",
weak=False,
)
m2m_changed.connect(
_role_permissions_changed,
sender=Role.permissions.through,
dispatch_uid="iam.role.permissions.m2m.invalidate_roles_cache",
weak=False,
)
Loading
Loading