Forum OpenACS Development: Getting the number of files created by an user in a community

Hi everyone,

I want to get the total number of files created by an user in a particular community. I was trying with the next query, but although it worked fine, it was very slow

select count (distinct it.item_id)
from acs_objects o, dotlrn_communities com, cr_items it
where it.item_id = o.object_id
and it.content_type='file_storage_object'
and o.creation_user = :user_id
and com.community_id= :community_id
and apm_package__parent_id(file_storage__get_package_id(it.item_id)) = com.package_id

So I am trying with this another query which uses the tree_sortkey field in acs_objects:

select count(*) from acs_objects a, acs_objects b
where b.object_id = :oneCom
and a.tree_sortkey between b.tree_sortkey
and tree_right(b.tree_sortkey)
and a.creation_user = :oneUser
and a.object_type = 'file_storage_object'

I think it works fine too and it's faster than the first one, but I am not completely sure if I am properly understanding the meaning of tree_sortkey field.

What do you think? Is it right?

Thanks,

David