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
43 stars 33 forks source link

Avoid excessive auto-subscription of Submission listeners. #1928

Closed kaladay closed 1 month ago

kaladay commented 2 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.

Notes for Future Work

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;
        }
    };
smutniak commented 1 month ago

I tested a couple things, i was mainly looking for other things it might have broken. I did notice that if am signed in on one browser and again under same acct using different browser (brave and firefox) my filter changes on one reflect on the other so some subscriptions are still working as expected.

I am confused about your branch though - your TAMUlib code is building 4.2.6 rather than 4.2.7 based on a 4 month old pom.xml rather than TDL's 3 week old pom.xml.

kaladay commented 1 month ago

I am confused about your branch though - your TAMUlib code is building 4.2.6 rather than 4.2.7 based on a 4 month old pom.xml rather than TDL's 3 week old pom.xml.

This has been corrected.