Index: openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl 16 Jul 2003 04:52:32 -0000 1.1 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl 18 Jul 2003 02:47:33 -0000 1.2 @@ -105,18 +105,29 @@ } { Gets all the ads assigned to categories - @param category_id_list A list of category ids. The system returns all ads mapped to these categories. + @param category_id_list A list of category ids. + The system returns all ads mapped to these categories, or + all ads if no category is passed. } { # DEDS: FIXME - this uses a subselect. this will get inefficient # when faced with a large db. optimize this. + # + # RBM: I think Deds was referring to the IN clause. It will get + # slow if there are lots of items in the list, but that + # doesn't seem to be the case. I made a small optimization + # to use 'and keyword_id = x' when opnly one category is + # passed. + set condition_stub "" + set n_categories [llength $category_id_list] - if {[llength $category_id_list]} { + if { $n_categories == 1 } { + set condition_stub "and keyword_id = [lindex $category_id_list 0]" + } elseif { $n_categories > 1 } { set condition_stub "and keyword_id in ([join $category_id_list ", "])" } set parent_id [classified-ads::get_folder_id -package_id [ad_conn package_id]] - return [db_list_of_ns_sets select_ads {}] }