Improve design to limit rendering latency for records with many properties #374

Merged
jsheunis merged 1 commit from many-parts into main 2026-07-08 12:28:52 +00:00
Owner

The problem this new approach aims to solve is the bad UX of waiting several
(tens of) seconds for a record with thousands of related nodes to render. It
came to light when rendering a file with thousands of parts. This is likely a
minor representation of the issue, which will worsen with larger records.

The new approach aims to do defer the maximum amount of processing until the
latest possible timepoint. Previous work in 3501e82380 already paved the way
for solving the current record rendering challenge. That commit introduced the
new record handling approach, a.k.a. maintaining a global list of items that is
incrementally updated when new nodes are added to or updated in the graph. This
global list of items also contains information about related nodes, preflabels,
and displayLabels. So it already calculated and contains information required
by the current record viewer, which currently ignored that and just recalculated
everything itself.

The new approach firstly involves minimal processing upfront when a record is
first fetched form the backend. It only indexes related nodes (not recursively)
but now in the structure expected by the NodeShapeViewer, i.e. divided into
termType triples. The minimally processed item that is now part of the global
list of items (recordItemsAll) is accessed in the NodeShapeViewer when it first
mounts. The NodeShapeViewer then takes an on-demand approach to processing
related nodes (i.e. its properties). For each property, on first mount it will
process up to the 'stepsize'-configured amount of values (e.g. 5) in order to
fetch nodes related to that property value and to calculate the display label
of that property value. Furthermore the same on-demand processing happens only
when the user hits the + button which changes the index-shown value of the
MoreOrLessRecordsViewer for that particular property. This replaces the previous
approach of the NodeShapeViewer where it calculated everything from scratch at
component mounting time using the quad prop.

Newly introduced functionality in the NodeShapeViewer includes:

  • updateItem() which is called in onBeforeMount. This function does additional minimal
    processing for all properties and values that will be rendered by default (i.e.
    they are fewer than the default displayed step size, e.g. 5. This minimal processing
    is handled by updateNamedNodeProperty() and updateBlankNodeProperty())
  • updateNamedNodeProperty() and updateBlankNodeProperty() update specific properties
    on-demand. Updating involves sometimes fetching related nodes and subsequently
    determining label details from related nodes. The point is to have readily available
    display label and preflabel information for rendering.
  • waitForRecordProcessing() is a new async function that allows waiting for a record
    in the global list of items to finish processing (after a triggered fetch) so that
    the NodeShapeViewer functionality can be sure that the item contains label details
    that are necessary for further processing.
  • when the NodeShapeViewer mounts, updateItem makes a structural copy from the associated
    item in recordItemsAll into a local reactive object, and does the rest of the processing
    for updating on that object. In contrast, after a record is edited and saved, the
    updateItem function builds up the item from scratch directly from the graph (using new
    useRecords utilities, specifically constructItem), i.e. it doesn't copy the state from
    recordItemsAll. This was necessary because the edited changes did not want to render as
    expected after a record save, if the normal updateItem was run. This issue caused much
    frustration and lots of wasted time trying to debug. The end-result, which now does what
    is expected, is therefore not in the current state by perfect design, but by necessity
    and as a solution to the to-me inexplicable Vue reactivity problem.
  • however many values of a given property is shown at any given time, all of those will be
    ordered alphanumerically; this means that the rendered index of a value might change
    if the user hits the + or - buttons to show more or fewer values of a property. This
    was done as a second-prize, to still allow sorting while not being able to sort all
    values since all values' display labels might not have been generated yet due to the
    new on-demand approach.

Another note on the waitForRecordProcessing() function and its use. When the
NodeShapeViewer uses fetchFromService to fetch a record, the expected outcome is that
the record is fetched and processed by useRecords' updateRecordItem function, and then
it ends up in recordItemsAll. It could be the case that the fetched record was already
in recordItemsAll prior to the fetch (in which case the fetch is skipped), or that the
record could not be fetched at all (perhaps it doesn't exist in the backend, perhaps
there was an http error). So the result from fetchFromService is first tested:

results?.status?.includes('success') || results?.status?.includes('skipped')

and only if this condition is met can we be certain that the record exists in recordItemsAll
and only then can waitForRecordProcessing be called without fear of a timeout error.
To support this process, the useData composable needed to be updated to:

  • check recordItemsAll rather than fetchedRequests for the pre-existence of the record
    (TODO: fetchedRequests seemed to suffer from a race condition and could not
    persistently and correctly pick up whether a record already existsed or was fetched
    or not)
  • also return the pid of the record that was skipped, specifically in the case of the
    'get-record' endpoint which is the one used in the NodeShapeViewer when a related
    record is fetched.

To support all of the above, the useRecords composable was updated to do the minimal upfront
processing and also to set a status flag when it has finished processing a new or
updated item. It also underwent a bit of refactoring to make the code more understandable
and allow the constructItem to be used in the composable as well as to be exported for
use by the NodeShapeViewer.

Lastly, to reduce onMount processing for the NodeShapeViewer even more, the backlink viewer
functionality was disabled, by commenting out the associated lines of code. It will
be brought back in a future commit, but via a user-clickable interface, i.e. it will
not be displayed upfront by default.

The problem this new approach aims to solve is the bad UX of waiting several (tens of) seconds for a record with thousands of related nodes to render. It came to light when rendering a file with thousands of parts. This is likely a minor representation of the issue, which will worsen with larger records. The new approach aims to do defer the maximum amount of processing until the latest possible timepoint. Previous work in 3501e82380 already paved the way for solving the current record rendering challenge. That commit introduced the new record handling approach, a.k.a. maintaining a global list of items that is incrementally updated when new nodes are added to or updated in the graph. This global list of items also contains information about related nodes, preflabels, and displayLabels. So it already calculated and contains information required by the current record viewer, which currently ignored that and just recalculated everything itself. The new approach firstly involves minimal processing upfront when a record is first fetched form the backend. It only indexes related nodes (not recursively) but now in the structure expected by the NodeShapeViewer, i.e. divided into termType triples. The minimally processed item that is now part of the global list of items (recordItemsAll) is accessed in the NodeShapeViewer when it first mounts. The NodeShapeViewer then takes an on-demand approach to processing related nodes (i.e. its properties). For each property, on first mount it will process up to the 'stepsize'-configured amount of values (e.g. 5) in order to fetch nodes related to that property value and to calculate the display label of that property value. Furthermore the same on-demand processing happens only when the user hits the + button which changes the index-shown value of the MoreOrLessRecordsViewer for that particular property. This replaces the previous approach of the NodeShapeViewer where it calculated everything from scratch at component mounting time using the quad prop. Newly introduced functionality in the NodeShapeViewer includes: - updateItem() which is called in onBeforeMount. This function does additional minimal processing for all properties and values that will be rendered by default (i.e. they are fewer than the default displayed step size, e.g. 5. This minimal processing is handled by updateNamedNodeProperty() and updateBlankNodeProperty()) - updateNamedNodeProperty() and updateBlankNodeProperty() update specific properties on-demand. Updating involves sometimes fetching related nodes and subsequently determining label details from related nodes. The point is to have readily available display label and preflabel information for rendering. - waitForRecordProcessing() is a new async function that allows waiting for a record in the global list of items to finish processing (after a triggered fetch) so that the NodeShapeViewer functionality can be sure that the item contains label details that are necessary for further processing. - when the NodeShapeViewer mounts, updateItem makes a structural copy from the associated item in recordItemsAll into a local reactive object, and does the rest of the processing for updating on that object. In contrast, after a record is edited and saved, the updateItem function builds up the item from scratch directly from the graph (using new useRecords utilities, specifically constructItem), i.e. it doesn't copy the state from recordItemsAll. This was necessary because the edited changes did not want to render as expected after a record save, if the normal updateItem was run. This issue caused much frustration and lots of wasted time trying to debug. The end-result, which now does what is expected, is therefore not in the current state by perfect design, but by necessity and as a solution to the to-me inexplicable Vue reactivity problem. - however many values of a given property is shown at any given time, all of those will be ordered alphanumerically; this means that the rendered index of a value might change if the user hits the + or - buttons to show more or fewer values of a property. This was done as a second-prize, to still allow sorting while not being able to sort all values since all values' display labels might not have been generated yet due to the new on-demand approach. Another note on the waitForRecordProcessing() function and its use. When the NodeShapeViewer uses fetchFromService to fetch a record, the expected outcome is that the record is fetched and processed by useRecords' updateRecordItem function, and then it ends up in recordItemsAll. It could be the case that the fetched record was already in recordItemsAll prior to the fetch (in which case the fetch is skipped), or that the record could not be fetched at all (perhaps it doesn't exist in the backend, perhaps there was an http error). So the result from fetchFromService is first tested: results?.status?.includes('success') || results?.status?.includes('skipped') and only if this condition is met can we be certain that the record exists in recordItemsAll and only then can waitForRecordProcessing be called without fear of a timeout error. To support this process, the useData composable needed to be updated to: - check recordItemsAll rather than fetchedRequests for the pre-existence of the record (TODO: fetchedRequests seemed to suffer from a race condition and could not persistently and correctly pick up whether a record already existsed or was fetched or not) - also return the pid of the record that was skipped, specifically in the case of the 'get-record' endpoint which is the one used in the NodeShapeViewer when a related record is fetched. To support all of the above, the useRecords composable was updated to do the minimal upfront processing and also to set a status flag when it has finished processing a new or updated item. It also underwent a bit of refactoring to make the code more understandable and allow the constructItem to be used in the composable as well as to be exported for use by the NodeShapeViewer. Lastly, to reduce onMount processing for the NodeShapeViewer even more, the backlink viewer functionality was disabled, by commenting out the associated lines of code. It will be brought back in a future commit, but via a user-clickable interface, i.e. it will not be displayed upfront by default.
After upgrading to linkml v1.11.1 the SHACL export of a schema had
different proprty shapes. Specifically the 'sh:datatype' triple was
gone and the 'sh:nodeKind' triple object changed to 'sh:IRI'. This
happened in the v1.11.0-rc1 release, and more specifically in the
https://github.com/linkml/linkml/pull/3291/changes/751ad5b056fc59f841bd4ef828d77a61b81f553f
commit.

shacl-vue still keeps backwards compatibility to allow matching the
URIEdtior for previous schema version property shapes.
The problem this new approach aims to solve is the bad UX of waiting several
(tens of) seconds for a record with thousands of related nodes to render. It
came to light when rendering a file with thousands of parts. This is likely a
minor representation of the issue, which will worsen with larger records.

The new approach aims to do defer the maximum amount of processing until the
latest possible timepoint. Previous work in 3501e82380 already paved the way
for solving the current record rendering challenge. That commit introduced the
new record handling approach, a.k.a. maintaining a global list of items that is
incrementally updated when new nodes are added to or updated in the graph. This
global list of items also contains information about related nodes, preflabels,
and displayLabels. So it already calculated and contains information required
by the current record viewer, which currently ignored that and just recalculated
everything itself.

The new approach firstly involves minimal processing upfront when a record is
first fetched form the backend. It only indexes related nodes (not recursively)
but now in the structure expected by the NodeShapeViewer, i.e. divided into
termType triples. The minimally processed item that is now part of the global
list of items (recordItemsAll) is accessed in the NodeShapeViewer when it first
mounts. The NodeShapeViewer then takes an on-demand approach to processing
related nodes (i.e. its properties). For each property, on first mount it will
process up to the 'stepsize'-configured amount of values (e.g. 5) in order to
fetch nodes related to that property value and to calculate the display label
of that property value. Furthermore the same on-demand processing happens only
when the user hits the + button which changes the index-shown value of the
MoreOrLessRecordsViewer for that particular property. This replaces the previous
approach of the NodeShapeViewer where it calculated everything from scratch at
component mounting time using the quad prop.

Newly introduced functionality in the NodeShapeViewer includes:
- updateItem() which is called in onBeforeMount. This function does additional minimal
  processing for all properties and values that will be rendered by default (i.e.
  they are fewer than the default displayed step size, e.g. 5. This minimal processing
  is handled by updateNamedNodeProperty() and updateBlankNodeProperty())
- updateNamedNodeProperty() and updateBlankNodeProperty() update specific properties
  on-demand. Updating involves sometimes fetching related nodes and subsequently
  determining label details from related nodes. The point is to have readily available
  display label and preflabel information for rendering.
- waitForRecordProcessing() is a new async function that allows waiting for a record
  in the global list of items to finish processing (after a triggered fetch) so that
  the NodeShapeViewer functionality can be sure that the item contains label details
  that are necessary for further processing.
- when the NodeShapeViewer mounts, updateItem makes a structural copy from the associated
  item in recordItemsAll into a local reactive object, and does the rest of the processing
  for updating on that object. In contrast, after a record is edited and saved, the
  updateItem function builds up the item from scratch directly from the graph (using new
  useRecords utilities, specifically constructItem), i.e. it doesn't copy the state from
  recordItemsAll. This was necessary because the edited changes did not want to render as
  expected after a record save, if the normal updateItem was run. This issue caused much
  frustration and lots of wasted time trying to debug. The end-result, which now does what
  is expected, is therefore not in the current state by perfect design, but by necessity
  and as a solution to the to-me inexplicable Vue reactivity problem.
- however many values of a given property is shown at any given time, all of those will be
  ordered alphanumerically; this means that the rendered index of a value might change
  if the user hits the + or - buttons to show more or fewer values of a property. This
  was done as a second-prize, to still allow sorting while not being able to sort all
  values since all values' display labels might not have been generated yet due to the
  new on-demand approach.

Another note on the waitForRecordProcessing() function and its use. When the
NodeShapeViewer uses fetchFromService to fetch a record, the expected outcome is that
the record is fetched and processed by useRecords' updateRecordItem function, and then
it ends up in recordItemsAll. It could be the case that the fetched record was already
in recordItemsAll prior to the fetch (in which case the fetch is skipped), or that the
record could not be fetched at all (perhaps it doesn't exist in the backend, perhaps
there was an http error). So the result from fetchFromService is first tested:

results?.status?.includes('success') || results?.status?.includes('skipped')

and only if this condition is met can we be certain that the record exists in recordItemsAll
and only then can waitForRecordProcessing be called without fear of a timeout error.
To support this process, the useData composable needed to be updated to:
- check recordItemsAll rather than fetchedRequests for the pre-existence of the record
  (TODO: fetchedRequests seemed to suffer from a race condition and could not
  persistently and correctly pick up whether a record already existsed or was fetched
  or not)
- also return the pid of the record that was skipped, specifically in the case of the
  'get-record' endpoint which is the one used in the NodeShapeViewer when a related
  record is fetched.

To support all of the above, the useRecords composable was updated to do the minimal upfront
processing and also to set a status flag when it has finished processing a new or
updated item. It also underwent a bit of refactoring to make the code more understandable
and allow the constructItem to be used in the composable as well as to be exported for
use by the NodeShapeViewer.

Lastly, to reduce onMount processing for the NodeShapeViewer even more, the backlink viewer
functionality was disabled, by commenting out the associated lines of code. It will
be brought back in a future commit, but via a user-clickable interface, i.e. it will
not be displayed upfront by default.
Sign in to join this conversation.
No description provided.