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
f24a99fa
Verified
Commit
f24a99fa
authored
6 months ago
by
magicfelix
Committed by
Jonathan Weth
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Optimize and drop unnecessary coursebook queries
parent
dd2685c6
No related branches found
No related tags found
1 merge request
!429
Resolve "Adapt to active school term"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/alsijil/models.py
+10
-8
10 additions, 8 deletions
aleksis/apps/alsijil/models.py
aleksis/apps/alsijil/schema/__init__.py
+3
-28
3 additions, 28 deletions
aleksis/apps/alsijil/schema/__init__.py
with
13 additions
and
36 deletions
aleksis/apps/alsijil/models.py
+
10
−
8
View file @
f24a99fa
...
@@ -139,7 +139,6 @@ class Documentation(CalendarEvent):
...
@@ -139,7 +139,6 @@ class Documentation(CalendarEvent):
events
:
list
,
events
:
list
,
incomplete
:
Optional
[
bool
]
=
False
,
incomplete
:
Optional
[
bool
]
=
False
,
absences_exist
:
Optional
[
bool
]
=
False
,
absences_exist
:
Optional
[
bool
]
=
False
,
request
:
Optional
[
HttpRequest
]
=
None
,
)
->
tuple
:
)
->
tuple
:
"""
Get all the documentations for the events.
"""
Get all the documentations for the events.
Create dummy documentations if none exist.
Create dummy documentations if none exist.
...
@@ -149,11 +148,15 @@ class Documentation(CalendarEvent):
...
@@ -149,11 +148,15 @@ class Documentation(CalendarEvent):
dummies
=
[]
dummies
=
[]
# Prefetch existing documentations to speed things up
# Prefetch existing documentations to speed things up
existing_documentations
=
Documentation
.
objects
.
filter
(
existing_documentations
=
(
datetime_start__lte
=
datetime_end
,
Documentation
.
objects
.
filter
(
datetime_end__gte
=
datetime_start
,
datetime_start__lte
=
datetime_end
,
amends__in
=
[
e
[
"
REFERENCE_OBJECT
"
]
for
e
in
events
],
datetime_end__gte
=
datetime_start
,
).
prefetch_related
(
"
participations
"
)
amends__in
=
[
e
[
"
REFERENCE_OBJECT
"
]
for
e
in
events
],
)
.
prefetch_related
(
"
participations
"
,
"
teachers
"
)
.
select_related
(
"
course
"
,
"
subject
"
)
)
for
event
in
events
:
for
event
in
events
:
if
incomplete
and
event
[
"
STATUS
"
]
==
"
CANCELLED
"
:
if
incomplete
and
event
[
"
STATUS
"
]
==
"
CANCELLED
"
:
...
@@ -214,7 +217,6 @@ class Documentation(CalendarEvent):
...
@@ -214,7 +217,6 @@ class Documentation(CalendarEvent):
start
:
datetime
,
start
:
datetime
,
end
:
datetime
,
end
:
datetime
,
incomplete
:
Optional
[
bool
]
=
False
,
incomplete
:
Optional
[
bool
]
=
False
,
request
:
Optional
[
HttpRequest
]
=
None
,
)
->
tuple
:
)
->
tuple
:
"""
Get all the documentations for the person from start to end datetime.
"""
Get all the documentations for the person from start to end datetime.
Create dummy documentations if none exist.
Create dummy documentations if none exist.
...
@@ -233,7 +235,7 @@ class Documentation(CalendarEvent):
...
@@ -233,7 +235,7 @@ class Documentation(CalendarEvent):
with_reference_object
=
True
,
with_reference_object
=
True
,
)
)
return
Documentation
.
get_documentations_for_events
(
start
,
end
,
events
,
incomplete
,
request
)
return
Documentation
.
get_documentations_for_events
(
start
,
end
,
events
,
incomplete
)
@classmethod
@classmethod
def
parse_dummy
(
def
parse_dummy
(
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/alsijil/schema/__init__.py
+
3
−
28
View file @
f24a99fa
...
@@ -4,7 +4,6 @@ from django.db.models import BooleanField, ExpressionWrapper, Q
...
@@ -4,7 +4,6 @@ from django.db.models import BooleanField, ExpressionWrapper, Q
import
graphene
import
graphene
import
graphene_django_optimizer
import
graphene_django_optimizer
from
guardian.shortcuts
import
get_objects_for_user
from
aleksis.apps.chronos.models
import
LessonEvent
from
aleksis.apps.chronos.models
import
LessonEvent
from
aleksis.apps.cursus.models
import
Course
from
aleksis.apps.cursus.models
import
Course
...
@@ -54,7 +53,6 @@ from .statistics import StatisticsByPersonType
...
@@ -54,7 +53,6 @@ from .statistics import StatisticsByPersonType
class
Query
(
graphene
.
ObjectType
):
class
Query
(
graphene
.
ObjectType
):
documentations
=
FilterOrderList
(
DocumentationType
)
documentations_by_course_id
=
FilterOrderList
(
documentations_by_course_id
=
FilterOrderList
(
DocumentationType
,
course_id
=
graphene
.
ID
(
required
=
True
)
DocumentationType
,
course_id
=
graphene
.
ID
(
required
=
True
)
)
)
...
@@ -101,19 +99,6 @@ class Query(graphene.ObjectType):
...
@@ -101,19 +99,6 @@ class Query(graphene.ObjectType):
group
=
graphene
.
ID
(
required
=
True
),
group
=
graphene
.
ID
(
required
=
True
),
)
)
@staticmethod
def
resolve_documentations
(
root
,
info
,
**
kwargs
):
qs
=
filter_active_school_term
(
info
.
context
,
Documentation
.
objects
.
all
(),
school_term_field
=
"
course__groups__school_term
"
,
)
if
not
info
.
context
.
user
.
has_perm
(
"
alsijil.view_documentation_rule
"
):
return
graphene_django_optimizer
.
query
(
get_objects_for_user
(
info
.
context
.
user
,
"
alsijil.view_documetation_rule
"
,
qs
),
info
)
return
graphene_django_optimizer
.
query
(
qs
,
info
)
def
resolve_documentations_by_course_id
(
root
,
info
,
course_id
,
**
kwargs
):
def
resolve_documentations_by_course_id
(
root
,
info
,
course_id
,
**
kwargs
):
documentations
=
Documentation
.
objects
.
filter
(
documentations
=
Documentation
.
objects
.
filter
(
pk__in
=
Documentation
.
objects
.
filter
(
course_id
=
course_id
)
pk__in
=
Documentation
.
objects
.
filter
(
course_id
=
course_id
)
...
@@ -173,23 +158,15 @@ class Query(graphene.ObjectType):
...
@@ -173,23 +158,15 @@ class Query(graphene.ObjectType):
)
)
school_term
=
get_active_school_term
(
info
.
context
)
school_term
=
get_active_school_term
(
info
.
context
)
q
=
Q
(
date_start
=
date_start
if
date_start
>
school_term
.
date_start
else
school_term
.
date_start
pk__in
=
LessonEvent
.
objects
.
filter
(
groups__school_term
=
school_term
)
date_end
=
date_end
if
date_end
<
school_term
.
date_end
else
school_term
.
date_end
.
values_list
(
"
id
"
,
flat
=
True
)
.
union
(
LessonEvent
.
objects
.
filter
(
course__groups__school_term
=
school_term
).
values_list
(
"
id
"
,
flat
=
True
)
)
)
qs
=
LessonEvent
.
objects
.
filter
(
q
)
events
=
LessonEvent
.
get_single_events
(
events
=
LessonEvent
.
get_single_events
(
datetime
.
combine
(
date_start
,
datetime
.
min
.
time
()),
datetime
.
combine
(
date_start
,
datetime
.
min
.
time
()),
datetime
.
combine
(
date_end
,
datetime
.
max
.
time
()),
datetime
.
combine
(
date_end
,
datetime
.
max
.
time
()),
info
.
context
,
info
.
context
,
event_params
,
event_params
,
with_reference_object
=
True
,
with_reference_object
=
True
,
queryset
=
qs
,
)
)
# Lookup or create documentations and return them all.
# Lookup or create documentations and return them all.
...
@@ -199,7 +176,6 @@ class Query(graphene.ObjectType):
...
@@ -199,7 +176,6 @@ class Query(graphene.ObjectType):
events
,
events
,
incomplete
,
incomplete
,
absences_exist
,
absences_exist
,
info
.
context
,
)
)
return
docs
+
dummies
return
docs
+
dummies
...
@@ -294,7 +270,6 @@ class Query(graphene.ObjectType):
...
@@ -294,7 +270,6 @@ class Query(graphene.ObjectType):
person
,
person
,
start
,
start
,
end
,
end
,
info
.
context
,
)
)
lessons_for_person
.
append
(
LessonsForPersonType
(
id
=
person
,
lessons
=
docs
+
dummies
))
lessons_for_person
.
append
(
LessonsForPersonType
(
id
=
person
,
lessons
=
docs
+
dummies
))
...
...
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