Skip to content

Commit

Permalink
Made the files tab search issue fewer queries; by issuing one non-nat…
Browse files Browse the repository at this point in the history
…ive query instead.

(only affects draft versions; for all others it was already using a single query)
  • Loading branch information
landreev committed Oct 30, 2015
1 parent 80d8c0f commit a690fa4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
38 changes: 23 additions & 15 deletions src/main/java/edu/harvard/iq/dataverse/DataFileServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,22 @@ public List<FileMetadata> findFileMetadataByDatasetVersionId(Long datasetVersion
}

public List<FileMetadata> findFileMetadataByDatasetVersionIdLabelSearchTerm(Long datasetVersionId, String searchTerm, String userSuppliedSortField, String userSuppliedSortOrder){

List <FileMetadata> retList = new ArrayList();
for (Integer id : findFileMetadataIdsByDatasetVersionIdLabelSearchTerm(datasetVersionId, searchTerm, userSuppliedSortField, userSuppliedSortOrder)){
retList.add( (FileMetadata) em.find(FileMetadata.class, id.longValue()));
}
return retList;
FileSortFieldAndOrder sortFieldAndOrder = new FileSortFieldAndOrder(userSuppliedSortField, userSuppliedSortOrder);

String sortField = sortFieldAndOrder.getSortField();
String sortOrder = sortFieldAndOrder.getSortOrder();
String searchClause = "";
if(searchTerm != null && !searchTerm.isEmpty()){
searchClause = " and (lower(o.label) like '%" + searchTerm.toLowerCase() + "%' or lower(o.description) like '%" + searchTerm.toLowerCase() + "%')";
}

String queryString = "select o from FileMetadata o where o.datasetVersion.id = :datasetVersionId"
+ searchClause
+ " order by o." + sortField + " " + sortOrder;
TypedQuery query = em.createQuery(queryString, FileMetadata.class);
query.setParameter("datasetVersionId", datasetVersionId);

return query.getResultList();
}

public List<Integer> findFileMetadataIdsByDatasetVersionIdLabelSearchTerm(Long datasetVersionId, String searchTerm, String userSuppliedSortField, String userSuppliedSortOrder){
Expand All @@ -192,7 +200,7 @@ public List<Integer> findFileMetadataIdsByDatasetVersionIdLabelSearchTerm(Long d
Query query = em.createNativeQuery("select o.id from FileMetadata o where o.datasetVersion_id = " + datasetVersionId
+ searchClause
+ " order by o." + sortField + " " + sortOrder);
System.out.print(query.toString());
//System.out.print(query.toString());

return query.getResultList();
}
Expand Down Expand Up @@ -285,7 +293,7 @@ public void findFileMetadataOptimizedExperimental(Dataset owner) { //, DatasetVe
}
dataTableResults = null;

logger.info("Retrieved "+dataTables.size()+" DataTable objects.");
logger.fine("Retrieved "+dataTables.size()+" DataTable objects.");

i = 0;
List<Object[]> dataTagsResults = em.createNativeQuery("SELECT t0.DATAFILE_ID, t0.TYPE FROM DataFileTag t0, dvObject t1 WHERE (t1.ID = t0.DATAFILE_ID) AND (t1.OWNER_ID="+ owner.getId() + ")").getResultList();
Expand All @@ -300,7 +308,7 @@ public void findFileMetadataOptimizedExperimental(Dataset owner) { //, DatasetVe
}
dataTagsResults = null;

logger.info("Retrieved "+i+" data tags.");
logger.fine("Retrieved "+i+" data tags.");

i = 0;

Expand Down Expand Up @@ -419,19 +427,19 @@ public void findFileMetadataOptimizedExperimental(Dataset owner) { //, DatasetVe
owner.setFiles(dataFiles);
fileResults = null;

logger.info("Retrieved and cached "+i+" datafiles.");
logger.fine("Retrieved and cached "+i+" datafiles.");

i = 0;
for (DataFileCategory fileCategory : owner.getCategories()) {
//logger.info("category: id="+fileCategory.getId());
//logger.fine("category: id="+fileCategory.getId());
categoryMap.put(fileCategory.getId(), i++);
}

logger.info("Retreived "+i+" file categories attached to the dataset.");
logger.fine("Retreived "+i+" file categories attached to the dataset.");

for (DatasetVersion version : owner.getVersions()) {
version.setFileMetadatas(retrieveFileMetadataForVersion(owner, version, filesMap, categoryMap));
logger.info("Retrieved "+version.getFileMetadatas().size()+" filemetadatas for the version "+version.getId());
logger.fine("Retrieved "+version.getFileMetadatas().size()+" filemetadatas for the version "+version.getId());
}
}

Expand Down Expand Up @@ -466,7 +474,7 @@ private List<FileMetadata> retrieveFileMetadataForVersion(Dataset dataset, Datas
categoryMetaMap.get(filemeta_id).add(category_id);
i++;
}
logger.info("Retrieved and mapped "+i+" file categories attached to files in the version "+version.getId());
logger.fine("Retrieved and mapped "+i+" file categories attached to files in the version "+version.getId());
categoryResults = null;

List<Object[]> metadataResults = em.createNativeQuery("select id, datafile_id, DESCRIPTION, LABEL, RESTRICTED from FileMetadata where datasetversion_id = "+version.getId()).getResultList();
Expand Down Expand Up @@ -525,7 +533,7 @@ private List<FileMetadata> retrieveFileMetadataForVersion(Dataset dataset, Datas

metadataResults = null;

logger.info("Retrieved "+retList.size()+" file metadatas for version "+version.getId()+" (inside the retrieveFileMetadataForVersion method).");
logger.fine("Retrieved "+retList.size()+" file metadatas for version "+version.getId()+" (inside the retrieveFileMetadataForVersion method).");


Collections.sort(retList, FileMetadata.compareByLabel);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ public String init() {
// Set Working Version and Dataset by PersistentID
dataset = datasetService.findByGlobalId(persistentId);
if (dataset != null) {
logger.info("retrived dataset, id="+dataset.getId());
logger.fine("retrived dataset, id="+dataset.getId());
}
retrieveDatasetVersionResponse = datasetVersionService.selectRequestedVersion(dataset.getVersions(), version);
//retrieveDatasetVersionResponse = datasetVersionService.retrieveDatasetVersionByPersistentId(persistentId, version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,13 +944,13 @@ public boolean userLoggedIn() {

public boolean publishedSelected() {
String expected = SearchFields.PUBLICATION_STATUS + ":\"" + getPUBLISHED() + "\"";
logger.info("published expected: " + expected + " actual: " + selectedTypesList);
logger.fine("published expected: " + expected + " actual: " + selectedTypesList);
return filterQueries.contains(SearchFields.PUBLICATION_STATUS + ":\"" + getPUBLISHED() + "\"");
}

public boolean unpublishedSelected() {
String expected = SearchFields.PUBLICATION_STATUS + ":\"" + getUNPUBLISHED() + "\"";
logger.info("unpublished expected: " + expected + " actual: " + selectedTypesList);
logger.fine("unpublished expected: " + expected + " actual: " + selectedTypesList);
return filterQueries.contains(SearchFields.PUBLICATION_STATUS + ":\"" + getUNPUBLISHED() + "\"");
}

Expand Down

0 comments on commit a690fa4

Please sign in to comment.