TexasDigitalLibrary / Vireo

Vireo is a turnkey Electronic Thesis and Dissertation (ETD) Management System.
https://texasdigitallibrary.atlassian.net/wiki/spaces/VUG/pages/87490642/About
GNU General Public License v2.0
46 stars 35 forks source link

Issue 1842: Improve load performance of type aheads, adding new end point for Vocabulary Word type aheads. #1845

Closed kaladay closed 1 year ago

kaladay commented 1 year ago

Partially resolves #1842

Address part of the performance problem with the type aheads by adding adding a delay (400ms for local data and 600ms for remote data). Create a new end point at /typeahead-vocabulary-word/ for the Controlled Vocabulary. This end point will perform a case-insensitive contains fetch, returning all matches. The matches themselves are reduced in size by using newly created SimpleVocabularyWordView and ContactsVocabularyWordView.

There are two directives that that need to be updated, each with a slightly different structure. For both cases, a standard typeAhead structure like the following is implemented:

{
    search: "some search string",
    loading: false,
    list: []
}

The search is the search to use. The loading is a boolean that designates whether or not the data is being asynchronously fetched. The loading allows for future work in adding something like a spinner or locking the field from edits until a response is received. The loading is otherwise not used or implemented before setting this up. The list is the list that contains that fetched array. The list is and should always be cleared using .length(0) rather than re-assignment because it is being asynchronously populated. The list ends up being used as the select list drop down.

The ControlledVocabularyRepo is updated to contain the new function typeAhead() that fetches the needed data. This function is wrapped in a defer promise so that the uib-typeahead knows that it is a callback and responds to the resolve() callback. Being a type ahead, this should always return an array on success or failure. On failure, an empty array is returned.

The Javascript unit tests are updated, adding tests for the new typeAhead. It seems that the directives have not always been fully tested in the past. This changes the mocking behavior to allow for the vocabulary repository to be mocked for potential testing in the directives. There are currently no thorough directive units tests written and so figuring out how to do the directive unit tests is left for another time. The Controlled Vocabulary Repository test is implemented and does do testing against the newly added typeAhead() repository method.

This does not address problems regarding the performance of the page loading and only addresses the type ahead performance problem. This is left to another commit or PR as appropriate.

Warning: There is an existing bug where the contacts Field Value for any Field Predicate does not show up on fresh page load. This is because the contacts in the FieldValue class is missing the needed @JsonView. This should be fixed to get the functionality in this commit fully working as expected.

The fix needs only be the following:

diff --git a/src/main/java/org/tdl/vireo/model/FieldValue.java b/src/main/java/org/tdl/vireo/model/FieldValue.java
index 83ee4ad852e5..c8f20ebd2f5b 100644
--- a/src/main/java/org/tdl/vireo/model/FieldValue.java
+++ b/src/main/java/org/tdl/vireo/model/FieldValue.java
@@ -36,6 +36,7 @@ public class FieldValue extends ValidatingBaseEntity {
     @Column(nullable = true)
     private String definition;

+    @JsonView(Views.SubmissionList.class)
     @ElementCollection(fetch = LAZY)
     @Fetch(FetchMode.SELECT)
     private List<String> contacts;