diff --git a/doc/release-notes/6.9-release-notes.md b/doc/release-notes/6.9-release-notes.md index 0211afc9acc..c49e4697096 100644 --- a/doc/release-notes/6.9-release-notes.md +++ b/doc/release-notes/6.9-release-notes.md @@ -95,6 +95,7 @@ See [the guides](https://guides.dataverse.org/en/6.9/developers/workflows.html#c - 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. - 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. - 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. +- Manage Gustbooks page was optimized to load much faster for collections with large numbers of downloads recorded. ## API Updates diff --git a/src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java b/src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java index a6da7de68c7..a6ac270b45c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java +++ b/src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java @@ -32,7 +32,9 @@ @Index(columnList = "datafile_id"), @Index(columnList = "datasetversion_id"), @Index(columnList = "authenticateduser_id"), - @Index(columnList = "dataset_id") + @Index(columnList = "dataset_id"), + @Index(columnList = "dataset_id, guestbook_id", name="INDEX_GUESTBOOKRESPONSE_dataset_id_guestbook_id"), + @Index(columnList = "dataset_id, eventtype", name="INDEX_GUESTBOOKRESPONSE_dataset_id_eventtype") }) @NamedQueries( diff --git a/src/main/java/edu/harvard/iq/dataverse/GuestbookResponseServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/GuestbookResponseServiceBean.java index a49845ce834..dcd62c9c0ff 100644 --- a/src/main/java/edu/harvard/iq/dataverse/GuestbookResponseServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/GuestbookResponseServiceBean.java @@ -488,17 +488,25 @@ public Long findCount30Days(Long dataverseId) { return (Long) query.getSingleResult(); } - public Long findCountAll() { - return findCountAll(null); - } - public Long findCountAll(Long dataverseId) { - String queryString; - if (dataverseId != null) { - queryString = "select count(o.id) from GuestbookResponse o, DvObject v where o.dataset_id = v.id and v.owner_id = " + dataverseId + " "; - } else { - queryString = "select count(o.id) from GuestbookResponse o "; + + if (dataverseId == null) { + return null; } + + // Note that this method used to support NULL dataverseId, + // in which case it counted ALL the guestbookresponse rows + // for the entire instance: + // queryString = "select count(o.id) from GuestbookResponse o "; + // I removed this code (it was not being used, thankfully) since + // the query can be insanely expensive on a large production table. + // That's why we use a stored procedure to "estimate" its size, in + // the dedicated getTotalDownloadCount() method further below, for + // example, when we need to show the total number of downloads on + // the homepage. (L.A.) + + 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 + " "; + Query query = em.createNativeQuery(queryString); return (Long) query.getSingleResult(); diff --git a/src/main/resources/db/migration/V6.8.0.4.sql b/src/main/resources/db/migration/V6.8.0.4.sql new file mode 100644 index 00000000000..6d2f3484b81 --- /dev/null +++ b/src/main/resources/db/migration/V6.8.0.4.sql @@ -0,0 +1,2 @@ +CREATE INDEX IF NOT EXISTS INDEX_GUESTBOOKRESPONSE_dataset_id_guestbook_id ON GUESTBOOKRESPONSE (dataset_id, guestbook_id); +CREATE INDEX IF NOT EXISTS INDEX_GUESTBOOKRESPONSE_dataset_id_eventtype ON GUESTBOOKRESPONSE (dataset_id, eventtype);