feat: improve asset loading - #484
Conversation
rayzhou-bit
left a comment
There was a problem hiding this comment.
Have one small change for you to look at. Overall, this looks great!
| }, | ||
| }, | ||
| "isRaw": false, | ||
| "showRawEditor": false, |
There was a problem hiding this comment.
I like this name change
| setImages: (state, { payload }) => ({ | ||
| ...state, | ||
| images: { ...state.images, ...payload.images }, | ||
| imageCount: payload.imageCount, |
There was a problem hiding this comment.
Shouldn't this add to the existing imageCount? I'm assuming imageCount should always reflect number of images
| imageCount: payload.imageCount, | |
| imageCount: state.imageCount + payload.imageCount, |
There was a problem hiding this comment.
The image count is the total number of assets in a course, not the number in the most recent fetch. The image count should be overwritten each time to make sure the most recent asset total on each fetch.
rayzhou-bit
left a comment
There was a problem hiding this comment.
LGTM! Note that problem editor calls api for advanced settings data which isn't mentioned in the description, but this is a necessary api call.
|
I did not mention that in the description because that API call is not part of the initialization call. |
Description
Remove unnecessary API calls
This PR improves the load time of the text editor, problem editor, and video editor. Previously all data that was required for any editor type at initialization was loaded, even if it was not necessary for the editor in-use. This means the text editor was loading course videos even it would never be using that data. Now the initialization function checks the editor and only calls the required APIs.
Reducing the need for all assets at load time
The need for all course assets to be fetched during initialization was removed. Now only the first fifty (50) images for a course are loaded for the text and problem editors. Previously all course assets were needed to update and write
/static/URLs, but assets all have a specific key pattern so the replace and set functions for the URLs are able to use a pattern matcher rather then copying data from the asset object.Adding Lazy Load for
SelectImageModalTo improve load time, the number of image assets fetched at load time was reduced to fifty (50), the default page size. However a course can have more than fifty images, so lazy loading was added to the
SelectImageModal. This makes it quicker to load the editor and makes it easier for the user to scroll through the images. In the case that there are only fifty images or less for a course or the images are being filter are less than or equal to fifty, the load more button will not appear.Supporting Information
JIRA Ticket: TNL-10869
Testing
fetchBlock,fetchUnit, andfetchImagesfetchBlock,fetchUnit,fetchVideos,fetchCourseDetailsView,fetchStudioViewasset-v1:{org}+{number+{run}+type@asset+block@{key_safe_name}/static/{key_safe_name}(aka the Studio URL)