Skip to content

Commit 405ab3c

Browse files
authored
Merge pull request DSpace#12305 from tinsch/make-signposting-endpoint-faster
Improve performance on signposting endpoint
2 parents c62186c + e655bcf commit 405ab3c

5 files changed

Lines changed: 31 additions & 3 deletions

File tree

dspace-api/src/main/java/org/dspace/content/BundleServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,4 +599,8 @@ public Bundle findByLegacyId(Context context, int id) throws SQLException {
599599
public int countTotal(Context context) throws SQLException {
600600
return bundleDAO.countRows(context);
601601
}
602+
603+
public int countBitstreams(Context context, Bundle bundle) throws SQLException {
604+
return bundleDAO.countBitstreams(context, bundle);
605+
}
602606
}

dspace-api/src/main/java/org/dspace/content/dao/BundleDAO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@
2222
*/
2323
public interface BundleDAO extends DSpaceObjectLegacySupportDAO<Bundle> {
2424
int countRows(Context context) throws SQLException;
25+
26+
int countBitstreams(Context context, Bundle bundle) throws SQLException;
2527
}

dspace-api/src/main/java/org/dspace/content/dao/impl/BundleDAOImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.sql.SQLException;
1111

12+
import jakarta.persistence.Query;
1213
import org.dspace.content.Bundle;
1314
import org.dspace.content.dao.BundleDAO;
1415
import org.dspace.core.AbstractHibernateDSODAO;
@@ -31,4 +32,13 @@ protected BundleDAOImpl() {
3132
public int countRows(Context context) throws SQLException {
3233
return count(createQuery(context, "SELECT count(*) from Bundle"));
3334
}
35+
36+
@Override
37+
public int countBitstreams(Context context, Bundle bundle) throws SQLException {
38+
Query query = createQuery(
39+
context, "SELECT count(bi.id) from Bundle bu join bu.bitstreams bi where bu.id = :bundleID"
40+
);
41+
query.setParameter("bundleID", bundle.getID());
42+
return count(query);
43+
}
3444
}

dspace-api/src/main/java/org/dspace/content/service/BundleService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,12 @@ public void moveBitstreamToBundle(Context context, Bundle targetBundle, Bitstre
146146
public void setOrder(Context context, Bundle bundle, UUID[] bitstreamIds) throws AuthorizeException, SQLException;
147147

148148
int countTotal(Context context) throws SQLException;
149+
150+
/**
151+
* Returns the count of bitstreams for the given bundle, performance optimized.
152+
*
153+
* @param context DSpace Context
154+
* @param bundle the bitstream bundle
155+
*/
156+
int countBitstreams(Context context, Bundle bundle) throws SQLException;
149157
}

dspace-server-webapp/src/main/java/org/dspace/app/rest/signposting/service/impl/LinksetServiceImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.dspace.content.Bundle;
2727
import org.dspace.content.DSpaceObject;
2828
import org.dspace.content.Item;
29+
import org.dspace.content.service.BundleService;
2930
import org.dspace.content.service.ItemService;
3031
import org.dspace.core.Constants;
3132
import org.dspace.core.Context;
@@ -48,6 +49,9 @@ public class LinksetServiceImpl implements LinksetService {
4849
@Autowired
4950
protected ItemService itemService;
5051

52+
@Autowired
53+
protected BundleService bundleService;
54+
5155
@Autowired
5256
private BitstreamMetadataReadPermissionEvaluatorPlugin bitstreamMetadataReadPermissionEvaluatorPlugin;
5357

@@ -86,7 +90,7 @@ public List<LinksetNode> createLinksetNodesForSingleLinkset(
8690

8791
List<LinksetNode> linksetNodes = new ArrayList<>();
8892
if (object.getType() == Constants.ITEM) {
89-
int itemBitstreamsCount = countItemBitstreams((Item) object);
93+
int itemBitstreamsCount = countItemBitstreams(context, (Item) object);
9094

9195
// Do not include individual bitstream typed links if their number exceeds
9296
// the limit in the configuration.
@@ -170,12 +174,12 @@ private Iterator<Bitstream> getItemBitstreams(Context context, Item item) {
170174
}
171175
}
172176

173-
private int countItemBitstreams(Item item) {
177+
private int countItemBitstreams(Context context, Item item) {
174178
try {
175179
int countBitstreams = 0;
176180
List<Bundle> bundles = itemService.getBundles(item, Constants.DEFAULT_BUNDLE_NAME);
177181
for (Bundle bundle: bundles) {
178-
countBitstreams += bundle.getBitstreams().size();
182+
countBitstreams += bundleService.countBitstreams(context, bundle);
179183
}
180184
return countBitstreams;
181185
} catch (SQLException e) {

0 commit comments

Comments
 (0)