mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 22:43:12 +00:00
Test metadata value cache
This commit is contained in:
@@ -13,19 +13,8 @@ import java.util.Date;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.JoinTable;
|
|
||||||
import javax.persistence.ManyToMany;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.OneToOne;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
import javax.persistence.Transient;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.content.comparator.NameAscendingComparator;
|
import org.dspace.content.comparator.NameAscendingComparator;
|
||||||
@@ -112,6 +101,16 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport {
|
|||||||
@Transient
|
@Transient
|
||||||
private transient ItemService itemService;
|
private transient ItemService itemService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if anything else was changed since last metadata retrieval()
|
||||||
|
* (to drive metadata cache)
|
||||||
|
*/
|
||||||
|
@Transient
|
||||||
|
private boolean modifiedMetadataCache = false;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private List<MetadataValue> cachedMetadata = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protected constructor, create object using:
|
* Protected constructor, create object using:
|
||||||
* {@link org.dspace.content.service.ItemService#create(Context, WorkspaceItem)}
|
* {@link org.dspace.content.service.ItemService#create(Context, WorkspaceItem)}
|
||||||
@@ -373,4 +372,23 @@ public class Item extends DSpaceObject implements DSpaceObjectLegacySupport {
|
|||||||
}
|
}
|
||||||
return itemService;
|
return itemService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setMetadataModified() {
|
||||||
|
super.setMetadataModified();
|
||||||
|
modifiedMetadataCache = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isModifiedMetadataCache() {
|
||||||
|
return modifiedMetadataCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<MetadataValue> getCachedMetadata() {
|
||||||
|
return cachedMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setCachedMetadata(List<MetadataValue> cachedMetadata) {
|
||||||
|
this.cachedMetadata = cachedMetadata;
|
||||||
|
modifiedMetadataCache = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1328,42 +1328,33 @@ prevent the generation of resource policy entry values with null dspace_object a
|
|||||||
@Override
|
@Override
|
||||||
public List<MetadataValue> getMetadata(Item item, String schema, String element, String qualifier, String lang,
|
public List<MetadataValue> getMetadata(Item item, String schema, String element, String qualifier, String lang,
|
||||||
boolean enableVirtualMetadata) {
|
boolean enableVirtualMetadata) {
|
||||||
//Fields of the relation schema are virtual metadata
|
if (!enableVirtualMetadata) {
|
||||||
//except for relation.type which is the type of item in the model
|
log.debug("Called getMetadata for " + item.getID() + " without enableVirtualMetadata");
|
||||||
if (StringUtils.equals(schema, MetadataSchemaEnum.RELATION.getName()) && !StringUtils.equals(element, "type")) {
|
return super.getMetadata(item, schema, element, qualifier, lang);
|
||||||
|
|
||||||
List<RelationshipMetadataValue> relationMetadata = relationshipMetadataService
|
|
||||||
.getRelationshipMetadata(item, enableVirtualMetadata);
|
|
||||||
List<MetadataValue> listToReturn = new LinkedList<>();
|
|
||||||
for (MetadataValue metadataValue : relationMetadata) {
|
|
||||||
if (StringUtils.equals(metadataValue.getMetadataField().getElement(), element)) {
|
|
||||||
listToReturn.add(metadataValue);
|
|
||||||
}
|
}
|
||||||
}
|
if (item.isModifiedMetadataCache()) {
|
||||||
listToReturn = sortMetadataValueList(listToReturn);
|
log.debug("Called getMetadata for " + item.getID() + " with invalid cache");
|
||||||
|
//rebuild cache
|
||||||
return listToReturn;
|
List<MetadataValue> dbMetadataValues = item.getMetadata();
|
||||||
|
|
||||||
} else {
|
|
||||||
List<MetadataValue> dbMetadataValues = super.getMetadata(item, schema, element, qualifier, lang);
|
|
||||||
|
|
||||||
List<MetadataValue> fullMetadataValueList = new LinkedList<>();
|
List<MetadataValue> fullMetadataValueList = new LinkedList<>();
|
||||||
if (enableVirtualMetadata) {
|
|
||||||
fullMetadataValueList.addAll(relationshipMetadataService.getRelationshipMetadata(item, true));
|
fullMetadataValueList.addAll(relationshipMetadataService.getRelationshipMetadata(item, true));
|
||||||
|
|
||||||
}
|
|
||||||
fullMetadataValueList.addAll(dbMetadataValues);
|
fullMetadataValueList.addAll(dbMetadataValues);
|
||||||
|
|
||||||
List<MetadataValue> finalList = new LinkedList<>();
|
item.setCachedMetadata(sortMetadataValueList(fullMetadataValueList));
|
||||||
for (MetadataValue metadataValue : fullMetadataValueList) {
|
|
||||||
if (match(schema, element, qualifier, lang, metadataValue)) {
|
|
||||||
finalList.add(metadataValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finalList = sortMetadataValueList(finalList);
|
|
||||||
return finalList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug("Called getMetadata for " + item.getID() + " based on cache");
|
||||||
|
// Build up list of matching values based on the cache
|
||||||
|
List<MetadataValue> values = new ArrayList<>();
|
||||||
|
for (MetadataValue dcv : item.getCachedMetadata()) {
|
||||||
|
if (match(schema, element, qualifier, lang, dcv)) {
|
||||||
|
values.add(dcv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an array of matching values
|
||||||
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user