pythonbrad / tamnza

Tamnza is a quiz application in which, teachers can create quizzes and students can sign up and take quizzes related to their interests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

perf: improve the query speed

pythonbrad opened this issue · comments

We need to improve the speed of the query via our ORM. By example:

  • limit the number of for loop to verify that a quiz is valid (contains questions and each question contains answers)

Bad performance

$questions = $quiz->questions;

if (count($questions) == 0) {
    # invalid
}

foreach ($questions as $question) {
    if (count($question->answers) == 0) {
        # invalid
    }
}

Why?

$quiz->questions and $question->answers use a loop to get the data to return.
Then we have too much iterations.

NB:

For a longtime improvement, consider the issue #1 .