Skip to content

Performance when retrieving units #9

@versae

Description

@versae

When a teacher is the owner of a bunch of courses, and units of that course have a lot of videos, the REST resource of the unit becomes really slow, resulting in a poor performance of the teachersadmin interface.

One of the problems I was able to identify was the is_teacher function, as reported in another issue. But the other one was the normalize_kq_weight. Here I propose a slightly modified version, not a powerful improvement, though.

def normalize_kq_weight(kq):
    from moocng.courses.models import KnowledgeQuantum
    unit_kq_list = KnowledgeQuantum.objects.filter(unit=kq.unit).values("weight")
    total_weight = 0
    for unit_kq in unit_kq_list:
        total_weight += unit_kq["weight"]
    if total_weight == 0:
        if len(unit_kq_list) == 0:
            return 0
        else:
            return 100.0 / len(unit_kq_list)
    return (kq.weight * 100.0) / total_weight

On the other hand, I think that a different reason could be that the is_teacher function is been called with all the courses instead of being called just with the course related to the unit. I'm not 100% sure, but please, take a look.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions