java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml | 19 +++
java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java | 48 ----------
java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java | 21 ++--
java/code/src/com/redhat/rhn/manager/rhnpackage/PackageManager.java | 17 +++
4 files changed, 50 insertions(+), 55 deletions(-)
New commits:
commit 15d04d2f146546a0ca4fcd1e9bb2224cc824ff47
Author: Justin Sherrill <jsherril(a)redhat.com>
Date: Thu Sep 2 12:05:40 2010 -0400
623447 - speeding up errata.listPackages api call
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
index 698f0a8..985a2cd 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml
@@ -1931,4 +1931,23 @@ select distinct p.evr_id as id
</mode>
+<mode name="package_dto_for_errata" class="com.redhat.rhn.frontend.dto.PackageDto">
+ <query params="eid">
+ select P.id, PN.name, evr.version, evr.release, PA.label as arch_label, evr.epoch, C.checksum, CT.label as checksum_type,
+ TO_CHAR(P.last_modified, 'YYYY-MM-DD HH24:MI:SS') AS last_modified
+ from rhnPackage P
+ inner join rhnErrataPackage EP on P.id = EP.package_id
+ inner join rhnPackageEvr evr on P.evr_id = evr.id
+ inner join rhnPackageName pn on P.name_id = PN.id
+ inner join rhnPackageArch PA on PA.id = P.package_arch_id
+ inner join rhnChecksum C on C.id = P.checksum_id
+ inner join rhnChecksumType CT on CT.id = C.CHECKSUM_TYPE_ID
+ where EP.errata_id = :eid
+
+ </query>
+</mode>
+
+
+
+
</datasource_modes>
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java
index 41eafea..3ae844e 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/ErrataHandler.java
@@ -32,6 +32,7 @@ import com.redhat.rhn.domain.rhnpackage.Package;
import com.redhat.rhn.domain.rhnpackage.PackageFactory;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.dto.CVE;
+import com.redhat.rhn.frontend.dto.PackageDto;
import com.redhat.rhn.frontend.xmlrpc.BaseHandler;
import com.redhat.rhn.frontend.xmlrpc.DuplicateErrataException;
import com.redhat.rhn.frontend.xmlrpc.InvalidAdvisoryReleaseException;
@@ -43,7 +44,6 @@ import com.redhat.rhn.frontend.xmlrpc.MissingErrataAttributeException;
import com.redhat.rhn.frontend.xmlrpc.NoChannelsSelectedException;
import com.redhat.rhn.frontend.xmlrpc.NoSuchChannelException;
import com.redhat.rhn.frontend.xmlrpc.PermissionCheckFailureException;
-import com.redhat.rhn.frontend.xmlrpc.packages.PackageHelper;
import com.redhat.rhn.manager.errata.ErrataManager;
import com.redhat.rhn.manager.errata.cache.ErrataCacheManager;
import com.redhat.rhn.manager.rhnpackage.PackageManager;
@@ -646,55 +646,15 @@ public class ErrataHandler extends BaseHandler {
* @xmlrpc.param #session_key()
* @xmlrpc.param #param("string", "advisoryName")
* @xmlrpc.returntype
- * #array()
- * #struct("package")
- * #prop("int", "id")
- * #prop("string", "name")
- * #prop("string", "epoch")
- * #prop("string", "version")
- * #prop("string", "release")
- * #prop("string", "arch_label")
- * #prop_array("providing_channels", "string", "- Channel label
- * providing this package.")
- * #prop("string", "build_host")
- * #prop("string", "description")
- * #prop("string", "checksum")
- * #prop("string", "vendor")
- * #prop("string", "summary")
- * #prop("string", "cookie")
- * #prop("string", "license")
- * #prop("string", "file")
- * #prop("string", "path")
- * #prop("string", "build_date")
- * #prop("string", "last_modified_date")
- * #prop("string", "size")
- * #prop("string", "payload_size")
- * #struct_end()
- * #array_end()
+ * $PackageDtoSerializer
*/
- public Object[] listPackages(String sessionKey, String advisoryName)
+ public List<PackageDto> listPackages(String sessionKey, String advisoryName)
throws FaultException {
// Get the logged in user
User loggedInUser = getLoggedInUser(sessionKey);
Errata errata = lookupErrata(advisoryName, loggedInUser.getOrg());
- //The set of packages for this erratum
- Set packages = errata.getPackages();
-
- //Main List containing the maps
- List returnList = new ArrayList();
-
- /*
- * Loop through the packages and add each one to the returnList array
- */
- for (Iterator itr = packages.iterator(); itr.hasNext();) {
- Package pkg = (Package) itr.next();
- // fill out a new row containing the package info map
- Map pmap = PackageHelper.packageToMap(pkg, loggedInUser);
- returnList.add(pmap);
- }
-
- return returnList.toArray();
+ return PackageManager.listPackageDtosForErrata(errata);
}
/**
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java
index 26534be..ffad0c0 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/errata/test/ErrataHandlerTest.java
@@ -29,6 +29,7 @@ import com.redhat.rhn.domain.rhnpackage.PackageEvr;
import com.redhat.rhn.domain.rhnpackage.PackageEvrFactory;
import com.redhat.rhn.domain.rhnpackage.test.PackageTest;
import com.redhat.rhn.domain.user.User;
+import com.redhat.rhn.frontend.dto.PackageDto;
import com.redhat.rhn.frontend.xmlrpc.InvalidAdvisoryReleaseException;
import com.redhat.rhn.frontend.xmlrpc.errata.ErrataHandler;
import com.redhat.rhn.frontend.xmlrpc.test.BaseHandlerTestCase;
@@ -249,16 +250,14 @@ public class ErrataHandlerTest extends BaseHandlerTestCase {
errata.addPackage(p);
ErrataManager.storeErrata(errata);
- Object[] pkgs = handler.listPackages(adminKey, errata.getAdvisory());
+ List<PackageDto> pkgs = handler.listPackages(adminKey, errata.getAdvisory());
assertNotNull(pkgs);
- assertEquals(errata.getPackages().size(), pkgs.length);
- assertTrue(pkgs.length > 0);
+ assertEquals(errata.getPackages().size(), pkgs.size());
+ assertTrue(pkgs.size() > 0);
boolean found = false;
- for (int i = 0; i < pkgs.length; i++) {
- Map pkg = (Map) pkgs[i];
- if (pkg.get("id").equals(p.getId())) {
- assertEquals(p.getBuildHost(), pkg.get("build_host"));
+ for (PackageDto pkg : pkgs) {
+ if (pkg.getId().equals(p.getId())) {
found = true;
}
}
@@ -270,7 +269,7 @@ public class ErrataHandlerTest extends BaseHandlerTestCase {
Errata errata = ErrataFactoryTest.createTestErrata(user.getOrg().getId());
ErrataManager.storeErrata(errata);
- int initialNumPkgs = handler.listPackages(adminKey, errata.getAdvisory()).length;
+ int initialNumPkgs = handler.listPackages(adminKey, errata.getAdvisory()).size();
Package pkg1 = PackageTest.createTestPackage(user.getOrg());
Package pkg2 = PackageTest.createTestPackage(user.getOrg());
@@ -284,7 +283,7 @@ public class ErrataHandlerTest extends BaseHandlerTestCase {
// verify
assertEquals(2, numPkgsAdded);
- int resultNumPkgs = handler.listPackages(adminKey, errata.getAdvisory()).length;
+ int resultNumPkgs = handler.listPackages(adminKey, errata.getAdvisory()).size();
assertEquals(initialNumPkgs + 2, resultNumPkgs);
boolean found1 = false, found2 = false;
@@ -309,7 +308,7 @@ public class ErrataHandlerTest extends BaseHandlerTestCase {
errata.addPackage(pkg2);
ErrataManager.storeErrata(errata);
- int initialNumPkgs = handler.listPackages(adminKey, errata.getAdvisory()).length;
+ int initialNumPkgs = handler.listPackages(adminKey, errata.getAdvisory()).size();
// execute
List<Integer> pkgIds = new ArrayList<Integer>();
@@ -319,7 +318,7 @@ public class ErrataHandlerTest extends BaseHandlerTestCase {
// verify
assertEquals(1, numPkgsRemoved);
- int resultNumPkgs = handler.listPackages(adminKey, errata.getAdvisory()).length;
+ int resultNumPkgs = handler.listPackages(adminKey, errata.getAdvisory()).size();
assertEquals(initialNumPkgs - 1, resultNumPkgs);
boolean found1 = false, found2 = false;
diff --git a/java/code/src/com/redhat/rhn/manager/rhnpackage/PackageManager.java b/java/code/src/com/redhat/rhn/manager/rhnpackage/PackageManager.java
index ce11de0..ed72ab3 100644
--- a/java/code/src/com/redhat/rhn/manager/rhnpackage/PackageManager.java
+++ b/java/code/src/com/redhat/rhn/manager/rhnpackage/PackageManager.java
@@ -40,6 +40,7 @@ import com.redhat.rhn.domain.role.RoleFactory;
import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.dto.PackageComparison;
+import com.redhat.rhn.frontend.dto.PackageDto;
import com.redhat.rhn.frontend.dto.UpgradablePackageListItem;
import com.redhat.rhn.frontend.listview.PageControl;
import com.redhat.rhn.frontend.xmlrpc.PermissionCheckFailureException;
@@ -1460,4 +1461,20 @@ public class PackageManager extends BaseManager {
}
+ /**
+ * List package's for an errata. This was mainly made for the errata xmlrpc handler
+ * was created to be fast.
+ * @param errata the errata
+ * @return list of Packages
+ */
+ public static List<PackageDto> listPackageDtosForErrata(Errata errata) {
+
+ SelectMode m = ModeFactory.getMode("Package_queries", "package_dto_for_errata");
+ Map params = new HashMap();
+ params.put("eid", errata.getId());
+
+ DataResult result = m.execute(params);
+ return result;
+ }
+
}