OpenMOOC / moocng

MOOC Engine
Apache License 2.0
88 stars 43 forks source link

Performance when retrieving units #9

Open versae opened 11 years ago

versae commented 11 years ago

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.