Hi guys,
Here is the patch, request for comments.
https://github.com/xning/koji/commit/4b5eeef34666f56097bbf099cd7d553b3ecce9b...
In the following cases, the listPackages method just do a simple query
1. no tagID, userID, and packageID.
2. inherited is not true or tagID is none.
In the 2nd case, the listPackages calls readPackageList method. When the 'with_dups' is true,
readPackageList will do following logic
##############code begin#######################
1. packages = {} 2. 3. for p in _multiRow(q, locals(), [pair[1] for pair in fields]): 4. # things are simpler for the first tag 5. pkgid = p['package_id'] 6. if with_dups: 7. packages.setdefault(pkgid,[]).append(p) 8. 9. else: 10. packages[pkgid] = p 11. 12. if tagID is None or (not inherit): 13. return packages
##############code end##########################
As follow SQL statment shows, we can let the postgres to do the above logic,
but we need return a json string or the pgdb will return a bit string.
From the json string, we can easily get a dict, hence the _multiRow method no need
to construct a dict by list comprehension. But seems we need change readPackageList.
##############code begin#######################
1. SELECT json_build_object(package_id, array_agg(row_to_json(f))) AS package_info FROM 2. 3. ( 4. SELECT 5. package.id AS package_id, package.name AS package_name, 6. tag.id AS tag_id, tag.name AS tag_name, 7. users.id AS owner_id, users.name AS owner_name, 8. extra_arches, tag_packages.blocked AS blocked 9. 10. FROM tag_packages 11. JOIN tag ON tag.id = tag_packages.tag_id 12. JOIN package ON package.id =tag_packages.package_id 13. JOIN users ON users.id = tag_packages.owner 14. 15. ) f GROUP BY package_id
##############code end##########################
Thanks a lot,
xning
koji-devel@lists.stg.fedorahosted.org