On Wednesday 17 May 2006 10:05, mulicheng wrote:
> I'm just curious.. I've wondered about this problem for a while. But
> what is the best practice for this type of relationship when selecting
> the child pages for display? I'm thinking of the case when a page has
> children who also have children and so on. Is it common practice to
> recursively query the database until all the children are selected? I
> can't think of any sql oriented way to select all the pages otherwise.
I let SQLObject do whatever it needs to give me child nodes in the easiest way
to loop possible. This means that SQLObject is doing a SELECT to get the
root node, then a SELECT to get all direct children. Then one SELECT per
child to get its children, and so on. This is fine for me, because I don't
descend the entire tree at any other time than site startup to build the
controller tree dynamically.
(This was the only way I could think of to reduce heavy SQL queries during
page views. Not having to look up every parent upon each request is nice.)
During startup of the site (start_extension) the entire content tree is
descended and controllers are instantiated and added dynamically. Once built
(which can take awhile for a large site) as all relevant data is already
in-memory, and individual requests are lightning fast. This is relying
heavily on SQLObject's singleton nature - a = Bob.get(1); b = Bob.get(1), a
is the same instance as b.
Of course, you can turn off this caching behavior and have .get() requests
done dynamically. Saves a LOT of memory, but is appropriately slower.
E.g. a site with two folders and two pages in each folder results in the
equivalent of the following:
class Root(RootController, CMSRoot):
def __init__(self):
self.firstfolder = CMSFolder(id=2, parent=self)
self.secondfolder = CMSFolder(id=3, parent=self)
self.firstfolder.pageA = CMSPage(id=4, parent=self.firstfolder)
self.firstfolder.pageB = CMSPage(id=5, parent=self.firstfolder)
self.secondfolder.pageA = CMSPage(id=6, parent=self.secondfolder)
self.secondfolder.pageB = CMSPage(id=7, parent=self.secondfolder)
My 2c.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---