Skip to content

Commit

Permalink
Merged in DSC-1460 (pull request DSpace#1514)
Browse files Browse the repository at this point in the history
[DSC-1460] DOIOrganiser performance improvements

Approved-by: Andrea Bollini
  • Loading branch information
LucaGiamminonni authored and abollini committed Mar 26, 2024
2 parents 05d06eb + 1082406 commit 55127b8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.handle.Handle;
import org.dspace.identifier.DOI;
import org.dspace.storage.rdbms.DatabaseConfigVO;
import org.hibernate.FlushMode;
import org.hibernate.Hibernate;
Expand Down Expand Up @@ -280,6 +281,11 @@ public <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLExcep
}
}

if (entity instanceof DOI) {
DOI doi = (DOI) entity;
uncacheEntity(doi.getDSpaceObject());
}

// ITEM
if (entity instanceof Item) {
Item item = (Item) entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ public String formatIdentifier(String identifier) throws DOIIdentifierException

@Override
public List<DOI> getDOIsByStatus(Context context, List<Integer> statuses) throws SQLException {
return doiDAO.findByStatus(context, statuses);
return doiDAO.findByStatus(context, statuses, -1, -1);
}

@Override
public List<DOI> getDOIsByStatus(Context context, List<Integer> statuses, int offset, int limit)
throws SQLException {
return doiDAO.findByStatus(context, statuses, offset, limit);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso, List<Integer
public List<DOI> findSimilarNotInState(Context context, String doi, List<Integer> statuses, boolean dsoNotNull)
throws SQLException;

public List<DOI> findByStatus(Context context, List<Integer> statuses) throws SQLException;
public List<DOI> findByStatus(Context context, List<Integer> statuses, int offset, int limit) throws SQLException;

public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso) throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public DOI findDOIByDSpaceObject(Context context, DSpaceObject dso, List<Integer
}

@Override
public List<DOI> findByStatus(Context context, List<Integer> statuses) throws SQLException {
public List<DOI> findByStatus(Context context, List<Integer> statuses, int offset, int limit) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, DOI.class);
Root<DOI> doiRoot = criteriaQuery.from(DOI.class);
Expand All @@ -80,7 +80,7 @@ public List<DOI> findByStatus(Context context, List<Integer> statuses) throws SQ
orPredicates.add(criteriaBuilder.equal(doiRoot.get(DOI_.status), status));
}
criteriaQuery.where(criteriaBuilder.or(orPredicates.toArray(new Predicate[] {})));
return list(context, criteriaQuery, false, DOI.class, -1, -1);
return list(context, criteriaQuery, false, DOI.class, limit, offset);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args
"Perform online deletion for all identifiers queued for deletion.");
options.addOption("q", "quiet", false,
"Turn the command line output off.");
options.addOption("o", "offset", true, "The records offset");
options.addOption("li", "limit", true, "The records limit");

Option filterDoi = Option.builder().optionalArg(true).longOpt("filter").hasArg().argName("filterName")
.desc("Use the specified filter name instead of the provider's filter. Defaults to a special " +
Expand Down Expand Up @@ -212,6 +214,17 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args
organiser.list("deletion", null, null, DOIIdentifierProvider.TO_BE_DELETED);
}

int limit = -1;
int offset = -1;

if (line.hasOption("li")) {
limit = Integer.valueOf(line.getOptionValue("li"));
}

if (line.hasOption("o")) {
offset = Integer.valueOf(line.getOptionValue("o"));
}

DOIService doiService = IdentifierServiceFactory.getInstance().getDOIService();
// Do we get a filter?
if (line.hasOption("filter")) {
Expand All @@ -224,7 +237,7 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args
if (line.hasOption('s')) {
try {
List<DOI> dois = doiService
.getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_RESERVED));
.getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_RESERVED), offset, limit);
if (dois.isEmpty()) {
System.err.println("There are no objects in the database "
+ "that could be reserved.");
Expand All @@ -243,7 +256,7 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args
if (line.hasOption('r')) {
try {
List<DOI> dois = doiService
.getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_REGISTERED));
.getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_REGISTERED), offset, limit);
if (dois.isEmpty()) {
System.err.println("There are no objects in the database "
+ "that could be registered.");
Expand All @@ -265,7 +278,7 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args
List<DOI> dois = doiService.getDOIsByStatus(context, Arrays.asList(
DOIIdentifierProvider.UPDATE_BEFORE_REGISTRATION,
DOIIdentifierProvider.UPDATE_RESERVED,
DOIIdentifierProvider.UPDATE_REGISTERED));
DOIIdentifierProvider.UPDATE_REGISTERED), offset, limit);
if (dois.isEmpty()) {
System.err.println("There are no objects in the database "
+ "whose metadata needs an update.");
Expand All @@ -284,7 +297,7 @@ public static void runCLI(Context context, DOIOrganiser organiser, String[] args
if (line.hasOption('d')) {
try {
List<DOI> dois = doiService
.getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_DELETED));
.getDOIsByStatus(context, Arrays.asList(DOIIdentifierProvider.TO_BE_DELETED), offset, limit);
if (dois.isEmpty()) {
System.err.println("There are no objects in the database "
+ "that could be deleted.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ public String formatIdentifier(String identifier)
*/
public List<DOI> getDOIsByStatus(Context context, List<Integer> statuses) throws SQLException;

/**
* Find all DOIs that have one of a given set of statuses.
* @param context current DSpace session.
* @param statuses desired statuses.
* @param offset offset value
* @param limit limited number of items
* @return all DOIs having any of the given statuses.
* @throws SQLException passed through.
*/
public List<DOI> getDOIsByStatus(Context context, List<Integer> statuses, int offset, int limit)
throws SQLException;

/**
* Find all DOIs that are similar to the specified pattern and not in the
* specified states.
Expand Down

0 comments on commit 55127b8

Please sign in to comment.