You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a somewhat big refactor of how we resolve values for previews internally.
Previously, for each document the studio was previewing, we'd fetch a version of the preview for each known release.
This created some overhead (althought the requests are batched), but most notably it caused an issue with previews ending up showing referenced values from the published version.
This is now solved by always applying the current perspective stack when fetching preview values. The perspective stack is applied recursively, so if a document type has someReference.title in it's preview config, the title of the referenced document will also reflect the current perspective (i.e. what the title is in the selected release).
Making the perspective apply to previews enabled me to remove some layering logic, since this is now done in the query that fetches the previews.
Using the just the current perspective stack poses a challenge: Sometimes you want to preview something that does not exist in the current perspective. For example: you are in the drafts perspective, but you want to preview a document that only exists as a version (i.e. it has neither a draft nor a published variant). This happens e.g. when previewing document list items or search results since we these collections using perspective=raw because we want people to still find version documents that exists outside of the current perspective.
For these cases, we always have a version id, so in these cases we'll fetch:
A preview for the document with current perspective applied
A preview for the document with the version perspective applied.
If the document doesn’t exist in the current perspective, it certainly exist in it’s own version perspective, so that means we’ll always have something to preview.
Things to note:
Since perspective applies to the query request, I had to change the preview observer batch fetcher memo to include the perspective stack as key.
The previous implementation fetched a preview version for each known release in order to answer "what other releases does this document exist in". This question can be answered more simply by fetching the _rev for each version document and check for existence (so no need to fetch the full preview). The information about what other version exists is now decoupled from previews entirely, and can be retrieved using the useDocumentVersionInfo()-hook. We no longer have preview for the version documents because we didn't have any use for that at the moment. We can always come back to that decision in the future, but for now, they return a stub with _id, _createdAt, _updatedAt, _rev, etc.
We were currently supporting a perspective for search, which only seems to apply to the global search atm. I took a chance on removing that, because I don't think that's desired. As of this PR, global search will use perspective=raw.
Other changes
Added a
Simplified the getPreviewStateObservable() so it no longer requires a fallback title – the fallback can trivially be applied in the consumer end, and it lead to a bunch of cases where we passed an empty string as the third argument.
What to review
This should be reviewed a bit carefully. Esp. in terms of API changes and naming (is it sensible and understandable?)
Testing
We have fairly good test coverage already, and e2e tests already made me aware of a few oversights. Would love some additional testing of everything related to previews, search and references e.g:
Document list previews
Global search
Adding documents to release
Searching document lists
Searching for references
Reference previews in Portable Text Editor, arrays and objects
Notes for release
Fixes a bug that caused previews to sometimes display values from published documents instead of drafts or versions.
Fixes a bug that caused documents outside of the current release to not appear in global search
Fixes a bug that would show "Missing document" for any document outside of the selected release without published or draft variants.
efps — editor "frames per second". The number of updates assumed to be possible within a second.
Derived from input latency. efps = 1000 / input_latency
Detailed information
🏠 Reference result
The performance result of sanity@latest
Benchmark
latency
p75
p90
p99
blocking time
test duration
article (title)
41ms
46ms
50ms
154ms
197ms
10.6s
article (body)
14ms
18ms
28ms
178ms
204ms
5.5s
article (string inside object)
36ms
39ms
43ms
308ms
340ms
7.1s
article (string inside array)
41ms
44ms
49ms
166ms
269ms
7.1s
recipe (name)
22ms
25ms
32ms
51ms
0ms
7.9s
recipe (description)
18ms
19ms
21ms
34ms
0ms
4.5s
recipe (instructions)
6ms
7ms
9ms
27ms
0ms
3.2s
🧪 Experiment result
The performance result of this branch
Benchmark
latency
p75
p90
p99
blocking time
test duration
article (title)
42ms
56ms
82ms
526ms
1016ms
11.9s
article (body)
15ms
17ms
28ms
179ms
251ms
5.8s
article (string inside object)
41ms
43ms
48ms
65ms
118ms
6.9s
article (string inside array)
44ms
46ms
51ms
236ms
250ms
7.2s
recipe (name)
22ms
24ms
27ms
56ms
1ms
7.6s
recipe (description)
21ms
22ms
23ms
69ms
8ms
5.1s
recipe (instructions)
5ms
7ms
8ms
26ms
0ms
3.3s
📚 Glossary
column definitions
benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
test duration — how long the test run took to complete.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This is a somewhat big refactor of how we resolve values for previews internally.
Previously, for each document the studio was previewing, we'd fetch a version of the preview for each known release.
This created some overhead (althought the requests are batched), but most notably it caused an issue with previews ending up showing referenced values from the published version.
This is now solved by always applying the current perspective stack when fetching preview values. The perspective stack is applied recursively, so if a document type has
someReference.title
in it's preview config, thetitle
of the referenced document will also reflect the current perspective (i.e. what thetitle
is in the selected release).Making the perspective apply to previews enabled me to remove some layering logic, since this is now done in the query that fetches the previews.
Using the just the current perspective stack poses a challenge: Sometimes you want to preview something that does not exist in the current perspective. For example: you are in the
drafts
perspective, but you want to preview a document that only exists as a version (i.e. it has neither a draft nor a published variant). This happens e.g. when previewing document list items or search results since we these collections using perspective=raw because we want people to still find version documents that exists outside of the current perspective.For these cases, we always have a version id, so in these cases we'll fetch:
If the document doesn’t exist in the current perspective, it certainly exist in it’s own version perspective, so that means we’ll always have something to preview.
Things to note:
useDocumentVersionInfo()
-hook. We no longer have preview for the version documents because we didn't have any use for that at the moment. We can always come back to that decision in the future, but for now, they return a stub with _id, _createdAt, _updatedAt, _rev, etc.Other changes
getPreviewStateObservable()
so it no longer requires a fallback title – the fallback can trivially be applied in the consumer end, and it lead to a bunch of cases where we passed an empty string as the third argument.What to review
This should be reviewed a bit carefully. Esp. in terms of API changes and naming (is it sensible and understandable?)
Testing
We have fairly good test coverage already, and e2e tests already made me aware of a few oversights. Would love some additional testing of everything related to previews, search and references e.g:
Notes for release