From cc08f69a558f04fcb30ca4be7b2f1d520e6020d3 Mon Sep 17 00:00:00 2001 From: Stephan Heunis Date: Wed, 8 Jul 2026 14:19:26 +0200 Subject: [PATCH] Improve design to limit rendering latency for records with many properties 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. --- src/components/FormEditor.vue | 3 + src/components/MoreOrLessRecordsViewer.vue | 7 +- src/components/NodeShapeViewer.vue | 698 ++++++++++++++------- src/components/ShaclVue.vue | 4 + src/components/ShaclVueRecords.vue | 2 + src/composables/useData.js | 30 +- src/composables/useRecords.js | 275 +++++--- 7 files changed, 717 insertions(+), 302 deletions(-) diff --git a/src/components/FormEditor.vue b/src/components/FormEditor.vue index 5764c68..d777c0e 100644 --- a/src/components/FormEditor.vue +++ b/src/components/FormEditor.vue @@ -220,6 +220,8 @@ provide('registerHandler', registerHandler); const show_all_fields = ref(false); provide('show_all_fields', show_all_fields); const fieldNotes = ref([]); +const recordItemsAll = inject('recordItemsAll'); + // ----------------- // // Lifecycle methods // @@ -369,6 +371,7 @@ async function saveForm() { ) { nodesToSubmit.value.push(saved_node); // we also need to add/update the record to the global list + recordItemsAll[saved_node.node_iri].status = null; rdfDS.emitAddedRecords([saved_node.node_iri]) } removeForm(saved_node); diff --git a/src/components/MoreOrLessRecordsViewer.vue b/src/components/MoreOrLessRecordsViewer.vue index f632866..7261fed 100644 --- a/src/components/MoreOrLessRecordsViewer.vue +++ b/src/components/MoreOrLessRecordsViewer.vue @@ -39,18 +39,21 @@