summaryrefslogtreecommitdiffstats
path: root/base/ca
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2015-07-14 19:47:15 -0400
committerEndi S. Dewata <edewata@redhat.com>2015-07-15 10:17:13 -0400
commitfca8dcbaa6a779a7685b935d1e216dbc775093f2 (patch)
tree6089ba187b54e030d5bae058b5d9ef19df3b6f48 /base/ca
parent9563c221a69d2cef894d814b21ffed646e238414 (diff)
downloadpki-fca8dcbaa6a779a7685b935d1e216dbc775093f2.tar.gz
pki-fca8dcbaa6a779a7685b935d1e216dbc775093f2.tar.xz
pki-fca8dcbaa6a779a7685b935d1e216dbc775093f2.zip
Fixed cert-find performance.
The CertService.searchCerts() has been modified to use the VLV properly to retrieve just the entries in the requested page, thus reducing the response time and memory requirement. Some classes have been modified to clean up the debugging logs.
Diffstat (limited to 'base/ca')
-rw-r--r--base/ca/src/org/dogtagpki/server/ca/rest/CertService.java38
1 files changed, 18 insertions, 20 deletions
diff --git a/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java b/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java
index e43909bbb..440f756de 100644
--- a/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java
+++ b/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java
@@ -70,6 +70,7 @@ import com.netscape.certsrv.cert.CertSearchRequest;
import com.netscape.certsrv.dbs.EDBRecordNotFoundException;
import com.netscape.certsrv.dbs.certdb.CertId;
import com.netscape.certsrv.dbs.certdb.ICertRecord;
+import com.netscape.certsrv.dbs.certdb.ICertRecordList;
import com.netscape.certsrv.dbs.certdb.ICertificateRepository;
import com.netscape.certsrv.logging.AuditFormat;
import com.netscape.certsrv.logging.ILogger;
@@ -442,47 +443,44 @@ public class CertService extends PKIService implements CertResource {
@Override
public Response searchCerts(CertSearchRequest data, Integer start, Integer size) {
+ CMS.debug("CertService.searchCerts()");
+
if (data == null) {
- throw new BadRequestException("Search request is null.");
+ throw new BadRequestException("Search request is null");
}
start = start == null ? 0 : start;
size = size == null ? DEFAULT_SIZE : size;
String filter = createSearchFilter(data);
- CMS.debug("CertService.searchCerts: filter: " + filter);
+ CMS.debug("CertService: filter: " + filter);
CertDataInfos infos = new CertDataInfos();
try {
- Enumeration<ICertRecord> e = repo.findCertRecords(filter);
- if (e == null) {
- throw new EBaseException("search results are null");
- }
+ ICertRecordList list = repo.findCertRecordsInList(filter, null, "serialno", size);
+ int total = list.getSize();
+ CMS.debug("CertService: total: " + total);
- int i = 0;
+ // return entries in the requested page
+ for (int i = start; i < start + size && i < total; i++) {
+ ICertRecord record = list.getCertRecord(i);
- // skip to the start of the page
- for (; i < start && e.hasMoreElements(); i++)
- e.nextElement();
+ if (record == null) {
+ CMS.debug("CertService: Certificate record not found");
+ throw new PKIException("Certificate record not found");
+ }
- // return entries up to the page size
- for (; i < start + size && e.hasMoreElements(); i++) {
- ICertRecord user = e.nextElement();
- infos.addEntry(createCertDataInfo(user));
+ infos.addEntry(createCertDataInfo(record));
}
- // count the total entries
- for (; e.hasMoreElements(); i++)
- e.nextElement();
-
- infos.setTotal(i);
+ infos.setTotal(total);
if (start > 0) {
URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", Math.max(start - size, 0)).build();
infos.addLink(new Link("prev", uri));
}
- if (start + size < i) {
+ if (start + size < total) {
URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", start + size).build();
infos.addLink(new Link("next", uri));
}