When you have about 30 question categories, the page that show it load to slow

When you have about 30 question categories, the page that show it load to slow

by Mr. Shortcut -
Number of replies: 16
Anyone has idea to solve it? Imagine that I create many categories for organizing questions. It's take a long time to load or insert/delete a category.
Average of ratings: -
In reply to Mr. Shortcut

Re: When you have about 30 question categories, the page that show it load to slow

by Tim Hunt -
Core developers колдонуучунун сүрөтү Documentation writers колдонуучунун сүрөтү Particularly helpful Moodlers колдонуучунун сүрөтү Peer reviewers колдонуучунун сүрөтү Plugin developers колдонуучунун сүрөтү
Which version are you using? I improved the performance of that part of the code a lot last summer, but I can't remember if that got into 1.6, or just 1.7 and later.
In reply to Tim Hunt

Re: When you have about 30 question categories, the page that show it load to slow

by Mr. Shortcut -
I am using version 1.7.1, when we have many many catergories, it take about 40 second or 1 minute to view or add a category.
In reply to Mr. Shortcut

Re: When you have about 30 question categories, the page that show it load to slow

by Tim Hunt -
Core developers колдонуучунун сүрөтү Documentation writers колдонуучунун сүрөтү Particularly helpful Moodlers колдонуучунун сүрөтү Peer reviewers колдонуучунун сүрөтү Plugin developers колдонуучунун сүрөтү
It really shouldn't be that slow. I don't suppose you have the skills to do a bit of debugging and try to pin down exactly which bit of the code is taking all the time?
In reply to Tim Hunt

Re: When you have about 30 question categories, the page that show it load to slow

by Mr. Shortcut -
I take a look at category_class.php in question folder. It seems we have PAGE_LENGTH constant for paging purpose when showing question category table but I can't see it work. Everytime I choose question category (URL shows look like http://localhost/question/category.php?id=1), it always show all categories in one page even if I change value of that constant. May be it's reason for loading slow. For example if you have 100 categories, you have wait util it load and transfer data for all of them. Is it right?
In reply to Mr. Shortcut

Re: When you have about 30 question categories, the page that show it load to slow

by Mr. Shortcut -
It seems paging function only work based on count of categoris level1.
In reply to Mr. Shortcut

Re: When you have about 30 question categories, the page that show it load to slow

by Tim Hunt -
Core developers колдонуучунун сүрөтү Documentation writers колдонуучунун сүрөтү Particularly helpful Moodlers колдонуучунун сүрөтү Peer reviewers колдонуучунун сүрөтү Plugin developers колдонуучунун сүрөтү
The trouble is that it is very hard to do paging with hierarchical categories. Also, when showing the question bank, you really need all the categories to be in the dropdown menus to be able to do all the things you might want to do.

However, is you only have 100 categories in total, it really should not be that show. 100 is a very small number in computer terms.

Oh, I see. the category_class.php file uses a different algorithm for building the category tree than the other pages.

in the initialize method in category_class.php, can you try replacing

$this->categories = $this->get_question_categories(null, "parent, sortorder, name ASC");

$this->categories = $this->arrange_categories($this->categories);

with

$this->categories = question_category_options($this->course->id);
In reply to Tim Hunt

Re: When you have about 30 question categories, the page that show it load to slow

by Mr. Shortcut -

Firstly, I tried to replace code as your suggestion but it's failed. That page can't load.

Secordly, you're right, we don't need paging the hierarchical in drop-down menu but I think we need to paging in the table below. As I understand, it only paging based on number of level1 categories right now. That's original source code is used to count all categories which have no parent.

foreach( $this->categories as $category ) {

if ($category->parent==0) {

++$count;

}

For example, we have 100 or 200 categories but only have 10 first level categories, so original approach still not do paging. It's difficult and slow for viewer when they try to view the table.

One more thing, when we try to drop one categories, its children moved to the same level as it automatically instead of deleteing cascade option.

Hope can get some suggestion from you in my case. Thank you very much.

In reply to Mr. Shortcut

Re: When you have about 30 question categories, the page that show it load to slow

by Tim Hunt -
Core developers колдонуучунун сүрөтү Documentation writers колдонуучунун сүрөтү Particularly helpful Moodlers колдонуучунун сүрөтү Peer reviewers колдонуучунун сүрөтү Plugin developers колдонуучунун сүрөтү
Is it difficult (slow) for you viewers when they look at the quiz editing screen? That screen contains two dropdown menus that list all the categories.

If the quiz editing screen displays quickly enough, then we know that it is possible to get all the categories form the database and display them quickly enough. Therefore, the category editing page must be written in an inefficient way and can be optimised.

If the quiz editing page is also slow, we have a bigger problem.

Sorry the change I suggested last night did not work. It seemed right, but I just typed it into the forum post - I did not have time to try it myself.

In reply to Tim Hunt

Re: When you have about 30 question categories, the page that show it load to slow

by Mr. Shortcut -
I think no problem with drop-down menu, it seems the speed slow because of category table that show all category for viewer. For example, we have 100 or 200 categories, so the table take a long time to be built without paging. Any suggestion?
In reply to Mr. Shortcut

Re: When you have about 30 question categories, the page that show it load to slow

by Tim Hunt -
Core developers колдонуучунун сүрөтү Documentation writers колдонуучунун сүрөтү Particularly helpful Moodlers колдонуучунун сүрөтү Peer reviewers колдонуучунун сүрөтү Plugin developers колдонуучунун сүрөтү
The point I am trying to make is that the dropdown menu lists all 100 or 200 categories. The slowest part of outputting either the dropdowns or the table this is getting the list of categories from the database and building the tree structure in memory. Printing the HTML is fast.

Therefore, the table of categories should be just as fast or slow as the dropdowns on the other pages.

At the moment printing the table is much slower. That is a bug. I know how to fix it, I just need to find the time.
In reply to Tim Hunt

Re: When you have about 30 question categories, the page that show it load to slow

by Mr. Shortcut -
Yeah. I see drop-down menu with all categories load fast but print table show too slow, even if row by row when we have many many categories. I've tried it many time and in different machine to make sure the problem don't come from network speed. Thank you for your help. I am looking forward to hear from you. I am also trying to find solution, too.
In reply to Mr. Shortcut

Re: When you have about 30 question categories, the page that show it load to slow

by Tim Hunt -
Core developers колдонуучунун сүрөтү Documentation writers колдонуучунун сүрөтү Particularly helpful Moodlers колдонуучунун сүрөтү Peer reviewers колдонуучунун сүрөтү Plugin developers колдонуучунун сүрөтү
Right, I think the attached zip file contains a fix. In there you will find a new version of category_class.php, and a file changes_to_questionlib.txt which details a section of questionlib.php that needs to be replaced with an updated version.

Can you try it and confirm that it works, and that it solves your performance problems. This is quite a big change, so if possible test it on a backup of your live site, not your production server.

I developed this against HEAD (1.9 dev), but it should work in 1.7+ too.
In reply to Tim Hunt

Re: When you have about 30 question categories, the page that show it load to slow

by Mr. Shortcut -
Thank you very much for your help. However, it seems drawing table still slow although I did the same steps as your guide. Drop-down menu is generated quickly but table is generated slowly.
In reply to Mr. Shortcut

Re: When you have about 30 question categories, the page that show it load to slow

by Tim Hunt -
Core developers колдонуучунун сүрөтү Documentation writers колдонуучунун сүрөтү Particularly helpful Moodlers колдонуучунун сүрөтү Peer reviewers колдонуучунун сүрөтү Plugin developers колдонуучунун сүрөтү
Thanks for trying it out.

Reworking the code made me realise what made this page so slow. Next to each category, there is a dropdown you can use to change the parent of each category. Each of those dropdowns is different. It is working out the contents of each of those dropdowns that is taking the time.

The only solution I can think of is to get rid of those dropdowns, if we do, then the only way to change the parent of a category would be by clicking on the edit category icon. What do people think?
In reply to Tim Hunt

Re: When you have about 30 question categories, the page that show it load to slow

by Mr. Shortcut -

I will try this one but hope to hear any ideas.

Thank you very much.

In reply to Tim Hunt

Re: When you have about 30 question categories, the page that show it load to slow

by Howard Miller -
Core developers колдонуучунун сүрөтү Documentation writers колдонуучунун сүрөтү Particularly helpful Moodlers колдонуучунун сүрөтү Peer reviewers колдонуучунун сүрөтү Plugin developers колдонуучунун сүрөтү
Just to jump in here... I did some work on this a while back (and it's probably why some of this code is so weird) because some people where using huge numbers of categories - we tested with 800 IIRC. With those numbers it used to failed completely. I rewrote the sort routines to make them more complicated but with a much better (number of swaps per category). I'm not sure it's related in this case but if it is any big changes should really check that they do not re-introduce any such problems.