Skip to content

Commit

Permalink
FIX get_students caching on all user query
Browse files Browse the repository at this point in the history
  • Loading branch information
wabscale committed Jan 29, 2022
1 parent a6f8383 commit 1cec30b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
10 changes: 5 additions & 5 deletions api/anubis/lms/students.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from anubis.utils.data import is_debug, is_job


@cache.memoize(timeout=-1, forced_update=is_debug, unless=is_debug)
@cache.memoize(timeout=-1, forced_update=is_debug, unless=is_debug, source_check=True)
def get_students(course_id: str = None) -> List[Dict[str, dict]]:
"""
Get students by course code. If no course code is specified,
Expand All @@ -18,13 +18,13 @@ def get_students(course_id: str = None) -> List[Dict[str, dict]]:
"""

# List of sqlalchemy filters
filters = []

if course_id is not None:
filters.append(InCourse.course_id == course_id)
users = User.query.join(InCourse).filter(InCourse.course_id == course_id).all()
else:
users = User.query.all()

# Get all users, and break them into their data props
return [s.data for s in User.query.join(InCourse).filter(*filters).all()]
return [s.data for s in users]


@cache.memoize(timeout=60, unless=is_debug)
Expand Down
18 changes: 6 additions & 12 deletions api/anubis/views/super/students.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
from typing import List
from flask import Blueprint

from flask import Blueprint

from anubis.lms.courses import assert_course_context, assert_course_superuser, course_context
from anubis.lms.repos import get_repos
from anubis.lms.students import get_students
from anubis.lms.theia import get_recent_sessions
from anubis.models import Assignment, Course, InCourse, Submission, User, db
from anubis.utils.auth.http import require_admin, require_superuser
from anubis.utils.auth.user import current_user
from anubis.utils.data import req_assert
from anubis.utils.http import get_number_arg, success_response
from anubis.utils.http.decorators import json_endpoint, json_response
from anubis.utils.auth.http import require_superuser
from anubis.utils.http import success_response
from anubis.utils.http.decorators import json_response

students_ = Blueprint("super-students", __name__, url_prefix="/super/students")


@students_.route("/list")
@require_superuser()
@json_response
def admin_students_list():
def super_students_list():
"""
List all users within the current course context
:return:
"""

# Get all students
students = [s.data for s in User.query.all()]
students = get_students(None)

# Pass back the students
return success_response({"students": students})
1 change: 1 addition & 0 deletions api/jobs/reaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def update_student_lists():
# Iterate through courses, updating student list
for course in courses:
get_students(course.id)
get_students(None)


@with_context
Expand Down

0 comments on commit 1cec30b

Please sign in to comment.