Skip to content

Commit 015ad0c

Browse files
authored
Manage Guestbooks page performance (#12053)
* A quick pr speeding up Manage Guestbooks page. * Removed the code that allowed to run "select count(o) from guestbookresponse", on the entire table. * Added another useful index on guestbookresponse table (that we've been using at HDV since April)
1 parent abc6d7c commit 015ad0c

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

doc/release-notes/6.9-release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ See [the guides](https://guides.dataverse.org/en/6.9/developers/workflows.html#c
9595
- In prior versions of Dataverse, publishing a dataset via the superuser-only update-current-version option would not set the current curation status (if enabled/used) to none/empty and, in v6.7, would not maintain the curation status history. These issues are now resolved and the update-current-version option works the same as normal publication of a new version with regard to curation status. See #11783 and #11784.
9696
- This release fixes problems with guestbook questions being displayed at download when files are selected from the dataset files table when guestbook-at-request is enabled and not displaying when they should when access is requested from the file page. See #11800, #11808, and #11835.
9797
- The optional Croissant exporter has been updated to 0.1.6 to prevent variable names, variable descriptions, and variable types from being exposed for restricted files. See https://github.com/gdcc/exporter-croissant/pull/20 and #11752.
98+
- Manage Gustbooks page was optimized to load much faster for collections with large numbers of downloads recorded.
9899

99100
## API Updates
100101

src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
@Index(columnList = "datafile_id"),
3333
@Index(columnList = "datasetversion_id"),
3434
@Index(columnList = "authenticateduser_id"),
35-
@Index(columnList = "dataset_id")
35+
@Index(columnList = "dataset_id"),
36+
@Index(columnList = "dataset_id, guestbook_id", name="INDEX_GUESTBOOKRESPONSE_dataset_id_guestbook_id"),
37+
@Index(columnList = "dataset_id, eventtype", name="INDEX_GUESTBOOKRESPONSE_dataset_id_eventtype")
3638
})
3739

3840
@NamedQueries(

src/main/java/edu/harvard/iq/dataverse/GuestbookResponseServiceBean.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,17 +488,25 @@ public Long findCount30Days(Long dataverseId) {
488488
return (Long) query.getSingleResult();
489489
}
490490

491-
public Long findCountAll() {
492-
return findCountAll(null);
493-
}
494-
495491
public Long findCountAll(Long dataverseId) {
496-
String queryString;
497-
if (dataverseId != null) {
498-
queryString = "select count(o.id) from GuestbookResponse o, DvObject v where o.dataset_id = v.id and v.owner_id = " + dataverseId + " ";
499-
} else {
500-
queryString = "select count(o.id) from GuestbookResponse o ";
492+
493+
if (dataverseId == null) {
494+
return null;
501495
}
496+
497+
// Note that this method used to support NULL dataverseId,
498+
// in which case it counted ALL the guestbookresponse rows
499+
// for the entire instance:
500+
// queryString = "select count(o.id) from GuestbookResponse o ";
501+
// I removed this code (it was not being used, thankfully) since
502+
// the query can be insanely expensive on a large production table.
503+
// That's why we use a stored procedure to "estimate" its size, in
504+
// the dedicated getTotalDownloadCount() method further below, for
505+
// example, when we need to show the total number of downloads on
506+
// the homepage. (L.A.)
507+
508+
String queryString = "select count(o.id) from GuestbookResponse o, DvObject v, Dataset d where o.dataset_id = v.id and v.id = d.id and v.owner_id = " + dataverseId + " ";
509+
502510

503511
Query query = em.createNativeQuery(queryString);
504512
return (Long) query.getSingleResult();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE INDEX IF NOT EXISTS INDEX_GUESTBOOKRESPONSE_dataset_id_guestbook_id ON GUESTBOOKRESPONSE (dataset_id, guestbook_id);
2+
CREATE INDEX IF NOT EXISTS INDEX_GUESTBOOKRESPONSE_dataset_id_eventtype ON GUESTBOOKRESPONSE (dataset_id, eventtype);

0 commit comments

Comments
 (0)