taskid 68458 optimize performance - IndexEventConsumer change

This commit is contained in:
Samuel
2020-01-31 13:14:44 +01:00
parent 48cf744040
commit 274ca1fcb2

View File

@@ -34,10 +34,10 @@ public class IndexEventConsumer implements Consumer {
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(IndexEventConsumer.class); private static Logger log = org.apache.logging.log4j.LogManager.getLogger(IndexEventConsumer.class);
// collect Items, Collections, Communities that need indexing // collect Items, Collections, Communities that need indexing
private Set<IndexableObject> objectsToUpdate = null; private Set<IndexableObject> objectsToUpdate = new HashSet<>();
// unique search IDs to delete // unique search IDs to delete
private Set<String> uniqueIdsToDelete = null; private Set<String> uniqueIdsToDelete = new HashSet<>();
IndexingService indexer = DSpaceServicesFactory.getInstance().getServiceManager() IndexingService indexer = DSpaceServicesFactory.getInstance().getServiceManager()
.getServiceByName(IndexingService.class.getName(), .getServiceByName(IndexingService.class.getName(),
@@ -154,19 +154,18 @@ public class IndexEventConsumer implements Consumer {
@Override @Override
public void end(Context ctx) throws Exception { public void end(Context ctx) throws Exception {
if (objectsToUpdate != null && uniqueIdsToDelete != null) { try {
// update the changed Items not deleted because they were on create list // update the changed Items not deleted because they were on create list
for (IndexableObject iu : objectsToUpdate) { for (IndexableObject iu : objectsToUpdate) {
/* we let all types through here and /* we let all types through here and
* allow the search indexer to make * allow the search indexer to make
* decisions on indexing and/or removal * decisions on indexing and/or removal
*/ */
iu.setIndexedObject(ctx.reloadEntity(iu.getIndexedObject())); ; iu.setIndexedObject(ctx.reloadEntity(iu.getIndexedObject()));
String uniqueIndexID = iu.getUniqueIndexID(); String uniqueIndexID = iu.getUniqueIndexID();
if (uniqueIndexID != null && !uniqueIdsToDelete.contains(uniqueIndexID)) { if (uniqueIndexID != null && !uniqueIdsToDelete.contains(uniqueIndexID)) {
try { try {
indexer.indexContent(ctx, iu, true, true); indexer.indexContent(ctx, iu, true, false);
log.debug("Indexed " log.debug("Indexed "
+ iu.getTypeText() + iu.getTypeText()
+ ", id=" + iu.getID() + ", id=" + iu.getID()
@@ -179,21 +178,24 @@ public class IndexEventConsumer implements Consumer {
for (String uid : uniqueIdsToDelete) { for (String uid : uniqueIdsToDelete) {
try { try {
indexer.unIndexContent(ctx, uid, true); indexer.unIndexContent(ctx, uid, false);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("UN-Indexed Item, handle=" + uid); log.debug("UN-Indexed Item, handle=" + uid);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Failed while UN-indexing object: " + uid, e); log.error("Failed while UN-indexing object: " + uid, e);
} }
} }
} finally {
if (!objectsToUpdate.isEmpty() || !uniqueIdsToDelete.isEmpty()) {
} indexer.commit();
// "free" the resources // "free" the resources
objectsToUpdate = null; objectsToUpdate.clear();
uniqueIdsToDelete = null; uniqueIdsToDelete.clear();
}
}
} }
@Override @Override