Forum OpenACS Development: Re: caching ns_sets

Collapse
2: Re: caching ns_sets (response to 1)
Posted by Ola Hansson on
How about this? Not extremely efficient perhaps, but you wouldn't have to change any other code...

ad_proc -public list_users {
        {-rel_type dotlrn_member_rel}
        community_id
    } {
        Returns the list of users with a membership_id, a user_id, 
first name,
        last name, email, and role.

        AKS: uncaching this until we figure out how to cache ns_sets 
correctly
    } {
#        return [dotlrn_community::list_users_not_cached \
#            -rel_type $rel_type \
#            -community_id $community_id
#        ]

        set users_list [util_memoize "dotlrn_community::list_users_not_cached \
            -rel_type $rel_type \
            -community_id $community_id
        "]

        # Convert to a list of ns_sets

        set ns_sets [list]

        foreach kv_pairs_list $users_list {
            lappend ns_sets [util_list_to_ns_set $kv_pairs_list]
        }

        return $ns_sets
    }



    ad_proc -private list_users_not_cached {
        {-rel_type:required}
        {-community_id:required}
    } {
        Memoizing helper
    } {
#       return [db_list_of_ns_sets select_users {}]

        set result [list]

        foreach ns_set [db_list_of_ns_sets select_users {}] {
            lappend result [util_ns_set_to_list -set $ns_set]
        }

        return $result
    }

Disclaimer: I have only tested it in parts...