Skip to content

Reduce api requests#1121

Merged
Arnei merged 23 commits intoopencast:mainfrom
Arnei:reduce-api-requests
Mar 20, 2025
Merged

Reduce api requests#1121
Arnei merged 23 commits intoopencast:mainfrom
Arnei:reduce-api-requests

Conversation

@Arnei
Copy link
Copy Markdown
Member

@Arnei Arnei commented Feb 25, 2025

Reduce the overall number of api requests we send to the backend when loading a new page/table. In particular, we were sending the same requests twice or more which should not be necessary. This cuts down on the number of requests in an attempt to reduce overall loading times. The guiding principle was that each component should be responsible for fetching its own data.

Should fix #940.

How to test this

Can be tested as usual. Switch between tables and modify the tables (filters, change page, change columns). Also check the requests in the network tab of your browser. (Note that if you test in development mode, due to React StrictMode being enabled requests will still be send twice).

Arnei added 16 commits February 18, 2025 13:53
The main navigation component fetches information
for the page it is loading. As far as I understand it,
the idea is to prefetch data to have it ready
on page load. This makes pages load slower. Furthermore, the page
itself still has to fetch that information anyway,
because it might be loaded by other means, meaning
we are doing the same (potentially expensive)
backend requests twice. Therefore, this patch
removes all backend requests from the main navigation component.
Ensure the redux state for "table" is completely cleared
when a page is loaded.
...which results in more lines of code, but also more readability.
When unmounting a page, dispatched actions
will continue to run in the background. This could cause the
wrong data being loaded into the table, because
the dispatched actions from one page would
complete later than the dispatched actions from another page.
This is most obvious when switching from
series to events and then quickly switching back to series.
This patch adds an interrupting mechanism that should
prevent the "loadIntoTable" action to be dispatched if the component
was unmounted.
    This should only be called if the filters were actually changed,
    not every time the TableFilters component is loaded.
    This could cause weird effects by sometimes loading the wrong data.
    This patch should fix that.
Much like the main navigation component, the navigation bar component
has no business fetching information from the backend that the component
would fetch by itself anyway.
Fetching data for a page would sometimes use the sorting params from
the previous page, as the "resource" variable had not yet updated in
the tableSlice. This could lead to wrong requests which then had to be
corrected by subsequent requests. So instead of relying on the
"resource" variable in the tableSlice, the fetching functions now
hardcode their respective resource.
When fetching events, we would then make subsequent backend calls and
await on each of them before returning. This would cause the response
time to be several seconds instead of milliseconds even for a low number
of events. This moves the subsequent backend calls into the component
that actually requires the information so it can make the calls itself
without delaying the table loading.
Apparently we can't just reset the whole tableSlice as we store
non-temporary information (sorting parameters for all tables)
in there. Therefore, this patch changes the reset function so that only
removes actual table contents.
The stats are not needed in the events component, and the
stats component is perfectly capable of fetching its own information.
No need to set an interval for every published cell, when
we could just make the call dependent on the row passed to it.
The events component repeatedly fetched stats before,
so now that the stats component is responsibly for it
it should do that as well.
Includes opencast#980, supersedes  opencast#1083.

Should achieve the same thing as opencast#1083, but without
reverting to older dependency versions. Meaning
clicking on a series name in the series table
should bring up the events table with the series filter set.
Including opencast#980 as it helps in achieving this.
They don't need to be dispatching all that.
The components will do it themselves when necessary.
Also only fetch filter information if we don't already have an
applicable filter in our redux store to save on loading times.
Some components are trying to set filters before loading a new table.
However, the react-router link will have loaded the new page
before the filters are actually set, leading to the display of
unfiltered data. This hopes to fix that by properly awaiting before
navigating.
@Arnei Arnei added the type:enhancement New feature or request label Feb 25, 2025
@github-actions
Copy link
Copy Markdown
Contributor

Use docker or podman to test this pull request locally.

Run test server using develop.opencast.org as backend:

podman run --rm -it -p 127.0.0.1:3000:3000 ghcr.io/opencast/opencast-admin-interface:pr-1121

Specify a different backend like stable.opencast.org:

podman run --rm -it -p 127.0.0.1:3000:3000 -e PROXY_TARGET=https://stable.opencast.org ghcr.io/opencast/opencast-admin-interface:pr-1121

It may take a few seconds for the interface to spin up.
It will then be available at http://127.0.0.1:3000.
For more options you can pass on to the proxy, take a look at the README.md.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 25, 2025

This pull request is deployed at test.admin-interface.opencast.org/1121/2025-03-19_09-34-07/ .
It might take a few minutes for it to become available.

The table limit (how many table entries should be shown) should
not be reset when swichting between tables apparently.
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 7, 2025

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

@snoesberger
Copy link
Copy Markdown
Contributor

I wanted to check the performance with this PR in our test environment, but unfortunately it looks like you need Opencast version 17 for this PR to work (we currently have version 16 installed).

However, my local tests of this PR, connected to https://stable.opencast.org, with various filters, switches between tabs etc. were successful. I also wanted to compare the performance when selecting a series in the series tab (as I did on #940), but this wasn't possible as the series filter on https://stable.opencast.org doesn't work at all at the moment.

Copy link
Copy Markdown
Contributor

@ferishili ferishili left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Arnei
Apart from the single code-related issue/suggestion, I found a few functional issues as follows:

Sorting issues:

Event Table

  • Date sorting does not work.
  • Start Time sorting does not work.
  • End Time sorting does not work.
  • Presenters sorting does not work.
  • Status (PublishCell) throws an error.
Screenshot 2025-03-13 at 14 13 13

Series Table

  • Organizer(s) sorting returns event 400 error!

Servers Table

  • Job completed sorting returns 400 error!

HTML Content Issue:

A dev-tool error appears:
In HTML, <button> cannot be a descendant of <button>.
This occurs due to two closing </button> elements, specifically in:
https://github.com/opencast/opencast-admin-interface/blob/ffde25bcd82d8aefc485acbdcbb20fb0b9ef6293/src/components/shared/Table.tsx#L307

This happens when selecting the table items num from the dropdown!

Bulk Checkbox Selector Issue

When the Events page first loads, the bulk select checkboxes are missing.
You need to switch between "Series" and "Events" for them to appear.

Some of the issues mentioned above might not be directly relevant to this PR. However, I am highlighting them here because I encountered them while performing functional testing on this PR.

Comment thread src/slices/tableSlice.ts Outdated
This patch fixes a bug that happened when switching pages
in the events table. Events that had no publication would be displayed
as having publications, if the event in its place on the previous page
had publications. For example, if the first event on page 1 had
publications, and then you would switch to page 2 where the first event
did not have publications, the event would be displayed as having
publications.

This patch fixes that by firstly resetting publication information
if the information changes. It also limits enriching to only happen if
the publications have changed.
@Arnei
Copy link
Copy Markdown
Member Author

Arnei commented Mar 14, 2025

Thanks for the extensive testing.

[...] sorting does not work

That should be fixed by backend PR opencast/opencast#6501. While the PR is already merged, I suppose it has not quite ended up on develop.opencast.org yet.

Status (PublishCell) throws an error.

Is hopefully addressed by latest commit d474710. If that is not the case, please described what exactly you did to provoke the error message. Please also describe if anything bad is happening in the ui.

[...] sorting returns event 400 error!

Good catch! As far as I can tell at a glance, these seem to be backend issues not caused by this PR. I'll open tickets for them.

HTML Content Issue: [...]

Also unrelated to this PR it seems, I will create a ticket for it.

Bulk Checkbox Selector Issue

Fixed by #1139 and #1150.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

Copy link
Copy Markdown
Contributor

@ferishili ferishili left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that everything works fine now.
However, sorting in the Series Table and Servers Table still returns a 400 error. I understand that this is more of a backend, but I still wanted to highlight it.

@ferishili ferishili self-requested a review March 20, 2025 06:47
Copy link
Copy Markdown
Contributor

@ferishili ferishili left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I would say this PR is good to go!
P.S.: Apologies for my previous mistaken review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Applying a "series" filter takes a long time

3 participants