Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Alsijil
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Alsijil
Commits
ab826b29
Verified
Commit
ab826b29
authored
Jun 5, 2024
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Avoid unnecessary queries to fetch related data
parent
f5c2d1a0
No related branches found
No related tags found
1 merge request
!360
Resolve "Add absence management to course book student dialog"
Pipeline
#188562
failed
Jun 5, 2024
Stage: prepare
Stage: test
Stage: build
Stage: publish
Stage: docker
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/apps/alsijil/managers.py
+25
-1
25 additions, 1 deletion
aleksis/apps/alsijil/managers.py
aleksis/apps/alsijil/models.py
+7
-1
7 additions, 1 deletion
aleksis/apps/alsijil/models.py
aleksis/apps/alsijil/schema/documentation.py
+1
-1
1 addition, 1 deletion
aleksis/apps/alsijil/schema/documentation.py
with
33 additions
and
3 deletions
aleksis/apps/alsijil/managers.py
+
25
−
1
View file @
ab826b29
...
...
@@ -11,7 +11,7 @@ from django.utils.translation import gettext as _
from
calendarweek
import
CalendarWeek
from
aleksis.apps.chronos.managers
import
DateRangeQuerySetMixin
from
aleksis.core.managers
import
AlekSISBaseManagerWithoutMigrations
from
aleksis.core.managers
import
AlekSISBaseManagerWithoutMigrations
,
PolymorphicBaseManager
if
TYPE_CHECKING
:
from
aleksis.core.models
import
Group
...
...
@@ -187,3 +187,27 @@ class GroupRoleAssignmentQuerySet(DateRangeQuerySetMixin, QuerySet):
def
for_group
(
self
,
group
:
"
Group
"
):
"""
Filter all role assignments for a group.
"""
return
self
.
filter
(
Q
(
groups
=
group
)
|
Q
(
groups__child_groups
=
group
))
class
DocumentationManager
(
PolymorphicBaseManager
):
"""
Manager adding specific methods to documentations.
"""
def
get_queryset
(
self
):
"""
Ensure often used related data are loaded as well.
"""
return
(
super
()
.
get_queryset
()
.
select_related
(
"
course
"
,
"
subject
"
,
)
.
prefetch_related
(
"
teachers
"
)
)
class
ParticipationStatusManager
(
PolymorphicBaseManager
):
"""
Manager adding specific methods to participation statuses.
"""
def
get_queryset
(
self
):
"""
Ensure often used related data are loaded as well.
"""
return
super
().
get_queryset
().
select_related
(
"
person
"
,
"
absence_reason
"
,
"
base_absence
"
)
This diff is collapsed.
Click to expand it.
aleksis/apps/alsijil/models.py
+
7
−
1
View file @
ab826b29
...
...
@@ -24,12 +24,14 @@ from aleksis.apps.alsijil.data_checks import (
PersonalNoteOnHolidaysDataCheck
,
)
from
aleksis.apps.alsijil.managers
import
(
DocumentationManager
,
GroupRoleAssignmentManager
,
GroupRoleAssignmentQuerySet
,
GroupRoleManager
,
GroupRoleQuerySet
,
LessonDocumentationManager
,
LessonDocumentationQuerySet
,
ParticipationStatusManager
,
PersonalNoteManager
,
PersonalNoteQuerySet
,
)
...
...
@@ -460,6 +462,8 @@ class Documentation(CalendarEvent):
# FIXME: DataCheck
objects
=
DocumentationManager
()
course
=
models
.
ForeignKey
(
Course
,
models
.
PROTECT
,
...
...
@@ -727,6 +731,8 @@ class ParticipationStatus(CalendarEvent):
# FIXME: DataChecks
objects
=
ParticipationStatusManager
()
person
=
models
.
ForeignKey
(
"
core.Person
"
,
models
.
CASCADE
,
related_name
=
"
participations
"
,
verbose_name
=
_
(
"
Person
"
)
)
...
...
@@ -760,7 +766,7 @@ class ParticipationStatus(CalendarEvent):
)
def
__str__
(
self
)
->
str
:
return
f
"
{
self
.
related_documentation
}
,
{
self
.
person
}
"
return
f
"
{
self
.
related_documentation
.
id
}
,
{
self
.
person
}
"
class
Meta
:
verbose_name
=
_
(
"
Participation Status
"
)
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/alsijil/schema/documentation.py
+
1
−
1
View file @
ab826b29
...
...
@@ -78,7 +78,7 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
# A dummy documentation will not have any participations
if
str
(
root
.
pk
).
startswith
(
"
DUMMY
"
)
or
not
hasattr
(
root
,
"
participations
"
):
return
[]
return
root
.
participations
.
all
()
return
root
.
participations
.
select_related
(
"
absence_reason
"
,
"
base_absence
"
).
all
()
class
DocumentationInputType
(
graphene
.
InputObjectType
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment