[Tutor] loops

A.T.Hofkamp a.t.hofkamp at tue.nl
Wed Apr 29 09:42:44 CEST 2009

Norman Khine wrote:
> hello,
> i have the following code:
> if unique_id is not None:
>     training = self.get_site_root()
>     from training import Training
>     # link back to news item
>     root = context.root
>     formats = ['itinerary', 'news']
>     for document in formats:
>         results = root.search(format=document, unique_id=unique_id)
>         if results:

Instead of processing results from each search directly, why not first collect 
results from all formats, followed by processing of the collected results?

ie something like

results = []
for doc in formats:

for result in results:

This does not give you better performance. However, it does give you the room 
to re-organize the searching.

In the above, you can now replace the first loop by something like

results = root.search_all_formats(formats, unique_id)

Does this help?


More information about the Tutor mailing list