Page 1 of 1

ContentOperations class and show_in_menu attribute

Posted: Mon Jun 06, 2011 9:34 pm
by Thijs
I'm having speed trouble with my CMSMS website (1.9.4.2) and i know what the issue is but i would like to know the reasoning behind the GetAllContentAsHierarchy function and maybe a solution that i am overlooking right now.

My situation is as follows. I have 30 pages with type 'Content'. I also have a UDT of which i would like to include into the search results of CMSMS. So i thought why not add an internal link for every possible result so that it would show up in the search results. There are 1400 possible results in this UDT so i have added 1400 pages of type 'Internal Link' with the show_in_menu attribute set to 0 because i only want them to show up in the search. If i use the default setup and load the website this will take alot of time:

Code: Select all

debug: (1.39307) - (usage: 7431664) - (peak: 7592996)

(postgres8): SELECT id_hierarchy,content_alias FROM cms_content ORDER BY hierarchy

Debug display of 'Start Loading Children into Tree':(1.416481) - (usage: 7688232) - (peak: 7713088)
Debug display of 'End Loading Children into Tree':(3.692203) - (usage: 9228976) - (peak: 9680156)
Debug: (3.692358) - (usage: 9229164) - (peak: 9680156)
This query is called everytime a page is loaded and i thought, why not add a 'WHERE show_in_menu = '1' ' clause. This speeded up the site again:

Code: Select all

Debug: (0.234564) - (usage: 7434708) - (peak: 7596804)

(postgres8): SELECT id_hierarchy,content_alias FROM cms_content where show_in_menu = '1' ORDER BY hierarchy

Debug display of 'Start Loading Children into Tree':(0.235227) - (usage: 7439140) - (peak: 7596804)
Debug display of 'End Loading Children into Tree':(0.241096) - (usage: 7564320) - (peak: 7605892)
Debug: (0.241175) - (usage: 7564508) - (peak: 7647284)
But then the pages longer show up in the search results (doh!). Any idea how i should approach this (besides from upgrading hw)? I can add a parameter to GetAllContentAsHierarchy and fix the search module to call it with that option but IMHO i cannot see the need to do a select on all the contents of the cms_content table if you are not going to use it. Can someone tell me why this is done? Perhaps a 'exclude not shown in menu' parameter for GetAllContentAsHierarchy is something to consider.

Re: ContentOperations class and show_in_menu attribute

Posted: Tue Jun 07, 2011 7:21 am
by Thijs
Having looked at the code implementing this is not as trivial as i thought because most modules just use the existing hierarchy manager. I assumed that every module did a seperate call to $contentops->GetAllContentAsHierarchy like in admin/listcontent.php .

Re: ContentOperations class and show_in_menu attribute

Posted: Tue Jun 07, 2011 4:06 pm
by calguy1000
So your having problems with your 'Rube Goldberg' machine eh.

Sounds like your yet another person that has solved a 'my paddle boat doesn't quite float level' problem, by adding an elephant.

A: The Content Tree is loaded from contentcache.php IF A: your timezones are set correctly both in mysql and on your server. it isn't requested from the database each time.

B: CMSMS is not designed to handle thousands of pages... dozens to a few hundred... for specific types of content, use a module that is specialized for that data type.

Re: ContentOperations class and show_in_menu attribute

Posted: Tue Jun 07, 2011 4:59 pm
by Thijs
calguy1000 wrote:So your having problems with your 'Rube Goldberg' machine eh.

Sounds like your yet another person that has solved a 'my paddle boat doesn't quite float level' problem, by adding an elephant.
Thx for the reply but not really an elephant. Just a mere beaver
calguy1000 wrote:A: The Content Tree is loaded from contentcache.php IF A: your timezones are set correctly both in mysql and on your server. it isn't requested from the database each time.
The timezones might be an issue but i was looking in the wrong place. This afternoon i took some time to dive into the code and found that the database query is not the issue. The real culprit is the load_from_list function. I noticed that the SQL query itself only takes 3ms but building the tree in load_from_list takes two seconds and it seems that this is the real bottleneck.

Code: Select all

Debug display of 'Start Loading Children into Tree':(0.22785) - (usage: 7442748) - (peak: 7610544)
Debug display of 'End Loading Children into Tree':(2.418447) - (usage: 9150952) - (peak: 9162500) 
I looked at the load_from_list code and integrated it into GetAllContentAsHierarchy as this is the only place you use it. This saves the concatenation, calling the function and one explode in load_from_list as you can create the tree using the SQL results. Probably not much but i did see a small improvement.
calguy1000 wrote:B: CMSMS is not designed to handle thousands of pages... dozens to a few hundred... for specific types of content, use a module that is specialized for that data type.
I do that, and that UDT has its own search which works great but i wanted to have a rudimentary integration with the CMS MS search because of my target audience. I just expected CMSMS to handle invisible intenral links in a different way but i can see why it was implemented the way it is.

Luckily it is open source and I adapted the code so that CMSMS will only look at 'show_in_menu=0' pages when it is needed. For example with the search or in the backend.