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
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
10 months ago
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
10 months ago
Stage: prepare
Stage: test
Stage: build
Stage: publish
Stage: docker
Changes
3
Pipelines
1
Hide 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 _
...
@@ -11,7 +11,7 @@ from django.utils.translation import gettext as _
from
calendarweek
import
CalendarWeek
from
calendarweek
import
CalendarWeek
from
aleksis.apps.chronos.managers
import
DateRangeQuerySetMixin
from
aleksis.apps.chronos.managers
import
DateRangeQuerySetMixin
from
aleksis.core.managers
import
AlekSISBaseManagerWithoutMigrations
from
aleksis.core.managers
import
AlekSISBaseManagerWithoutMigrations
,
PolymorphicBaseManager
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
aleksis.core.models
import
Group
from
aleksis.core.models
import
Group
...
@@ -187,3 +187,27 @@ class GroupRoleAssignmentQuerySet(DateRangeQuerySetMixin, QuerySet):
...
@@ -187,3 +187,27 @@ class GroupRoleAssignmentQuerySet(DateRangeQuerySetMixin, QuerySet):
def
for_group
(
self
,
group
:
"
Group
"
):
def
for_group
(
self
,
group
:
"
Group
"
):
"""
Filter all role assignments for a group.
"""
"""
Filter all role assignments for a group.
"""
return
self
.
filter
(
Q
(
groups
=
group
)
|
Q
(
groups__child_groups
=
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 (
...
@@ -24,12 +24,14 @@ from aleksis.apps.alsijil.data_checks import (
PersonalNoteOnHolidaysDataCheck
,
PersonalNoteOnHolidaysDataCheck
,
)
)
from
aleksis.apps.alsijil.managers
import
(
from
aleksis.apps.alsijil.managers
import
(
DocumentationManager
,
GroupRoleAssignmentManager
,
GroupRoleAssignmentManager
,
GroupRoleAssignmentQuerySet
,
GroupRoleAssignmentQuerySet
,
GroupRoleManager
,
GroupRoleManager
,
GroupRoleQuerySet
,
GroupRoleQuerySet
,
LessonDocumentationManager
,
LessonDocumentationManager
,
LessonDocumentationQuerySet
,
LessonDocumentationQuerySet
,
ParticipationStatusManager
,
PersonalNoteManager
,
PersonalNoteManager
,
PersonalNoteQuerySet
,
PersonalNoteQuerySet
,
)
)
...
@@ -460,6 +462,8 @@ class Documentation(CalendarEvent):
...
@@ -460,6 +462,8 @@ class Documentation(CalendarEvent):
# FIXME: DataCheck
# FIXME: DataCheck
objects
=
DocumentationManager
()
course
=
models
.
ForeignKey
(
course
=
models
.
ForeignKey
(
Course
,
Course
,
models
.
PROTECT
,
models
.
PROTECT
,
...
@@ -727,6 +731,8 @@ class ParticipationStatus(CalendarEvent):
...
@@ -727,6 +731,8 @@ class ParticipationStatus(CalendarEvent):
# FIXME: DataChecks
# FIXME: DataChecks
objects
=
ParticipationStatusManager
()
person
=
models
.
ForeignKey
(
person
=
models
.
ForeignKey
(
"
core.Person
"
,
models
.
CASCADE
,
related_name
=
"
participations
"
,
verbose_name
=
_
(
"
Person
"
)
"
core.Person
"
,
models
.
CASCADE
,
related_name
=
"
participations
"
,
verbose_name
=
_
(
"
Person
"
)
)
)
...
@@ -760,7 +766,7 @@ class ParticipationStatus(CalendarEvent):
...
@@ -760,7 +766,7 @@ class ParticipationStatus(CalendarEvent):
)
)
def
__str__
(
self
)
->
str
:
def
__str__
(
self
)
->
str
:
return
f
"
{
self
.
related_documentation
}
,
{
self
.
person
}
"
return
f
"
{
self
.
related_documentation
.
id
}
,
{
self
.
person
}
"
class
Meta
:
class
Meta
:
verbose_name
=
_
(
"
Participation Status
"
)
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
...
@@ -78,7 +78,7 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp
# A dummy documentation will not have any participations
# A dummy documentation will not have any participations
if
str
(
root
.
pk
).
startswith
(
"
DUMMY
"
)
or
not
hasattr
(
root
,
"
participations
"
):
if
str
(
root
.
pk
).
startswith
(
"
DUMMY
"
)
or
not
hasattr
(
root
,
"
participations
"
):
return
[]
return
[]
return
root
.
participations
.
all
()
return
root
.
participations
.
select_related
(
"
absence_reason
"
,
"
base_absence
"
).
all
()
class
DocumentationInputType
(
graphene
.
InputObjectType
):
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