TAMULib / Vireo

Vireo is a turnkey Electronic Thesis and Dissertation (ETD) Management System.
http://vireoetd.org/vireo/
1 stars 0 forks source link

Avoid excessive auto-subscription of Submission listeners. #78

Closed kaladay closed 4 months ago

kaladay commented 4 months ago

The Submission model in the UI is adding 4 or more listeners on instantiation. This causes every open browser to receive an auto-subscription for every newly created Submission. Then for every change done, the browsers receive this.

This is particularly bad when:

  1. The current browser page has nothing related to the newly added or recently modified Submission.
  2. Numerous Submissions are created while a given browser page is open.
  3. Numerous already subscribed Submissions are updated while a given browser page is open.

The browser resources become excessively used and abused, slowing down the performance and response time of a browser. Reloading the page is often the only way to clean this up.

This redesigns the Submission model to move the subscription into a manually called function (enableListeners()). This enableListeners() function is then explicitly called for all cases where a Submission should be listened to.

The enableListeners() function accepts an argument called simple that when true loads a reduced set of the standard Submission listeners. This is useful for pages that only care about basic information and not detailed information. This should help reduce the burden on the browser and potentially increase performance.

A review of the list table shows that the list table already does not update dynamically. No changes are made to make the list table update dynamically.

These changes partially resolves https://github.com/TexasDigitalLibrary/Vireo/issues/1885 . The removed listener is present but when a remove is performed the page does not refresh.

The following are places that have been tested and should be tested:

The "Welcome Page" and the "Admin Submission List Page" are not expected to update on changes. The others should be reviewed to confirm that the Submission changes are updated while edited in another webbrowser page.

A Submission.disableListneers() function might be useful.

Example addition to the submission:

        submission.disableListeners = function (simple) {
            if (angular.isUndefined(submission.id)) {
                return;
            }

            var fieldValuesListen = apiMapping.Submission.fieldValuesListen;
            var fieldValuesRemovedListen = apiMapping.Submission.fieldValueRemovedListen;

            WsService.unsubscribe(fieldValuesListen.endpoint + "/" + fieldValuesListen.controller + "/" + submission.id + "/field-values");
            WsService.unsubscribe(fieldValuesRemovedListen.endpoint + "/" + fieldValuesRemovedListen.controller + "/" + submission.id + "/removed-field-values");

            delete submission.fieldValuesListenPromise;
            delete submission.fieldValuesRemovedListenPromise;

            if (simple !== true) {
                var actionLogListen = apiMapping.Submission.actionLogListen;
                var customActionValuesListen = apiMapping.Submission.customActionValuesListen;

                WsService.unsubscribe(fieldValuesListen.endpoint + "/" + fieldValuesListen.controller + "/" + submission.id + "/action-logs");
                WsService.unsubscribe(fieldValuesRemovedListen.endpoint + "/" + fieldValuesRemovedListen.controller + "/" + submission.id + "/custom-action-values");

                delete submission.actionLogListenPromise;
                delete submission.customActionValuesListenPromise;

                delete submission.actionLogListenReloadDefer;
            }
        };

Example addition to the mocks:

    model.disableListeners = function (simple) {
        delete model.fieldValuesListenPromise;
        delete model.fieldValuesRemovedListenPromise;

        if (simple !== true) {
            delete model.actionLogListenPromise;
            delete model.customActionValuesListenPromise;

            delete model.actionLogListenReloadDefer;
        }
    };
kaladay commented 4 months ago

We decided to hold off from publishing this locally and will make a new PR of this directly to upstream.

See: https://github.com/TexasDigitalLibrary/Vireo/pull/1928