Commit 1d00a99b authored by Robert Knight's avatar Robert Knight

Fetch annotations in parallel with groups and profile where possible

Currently both the sidebar and notebook wait until the user's profile and groups are
fetched before fetching annotations. This is because the search query to
fetch annotations depends on the focused group. The groups query may
take several hundred ms to complete, so this ends up delaying the
initial fetch and display of annotations by that amount of time.

In the notebook the common case is that the user is already logged in
and the notebook is configured to display a specific group ("the direct
linked group"): whatever the user had previously selected in the sidebar.
In this scenario it is very likely that the direct-linked group will end
up being the focused one after groups are fetched.

Based on these assumptions, we can speed up the initial annotation by
loading annotations from the direct-linked group. If the focused group
ends up being different, annotations will just be re-fetched from the
correct group once that is known.
parent 8d237661
...@@ -34,6 +34,13 @@ function NotebookView({ loadAnnotationsService }) { ...@@ -34,6 +34,13 @@ function NotebookView({ loadAnnotationsService }) {
const groupName = focusedGroup?.name ?? '…'; const groupName = focusedGroup?.name ?? '…';
// Get the ID of the group to fetch annotations from. Once groups are fetched
// this is the same as the focused group ID. In the case where the notebook
// is configured to open with a specific group we can start fetching annotations
// sooner, without waiting for the group fetch to complete, by falling back
// to the initially-configured group.
const groupId = focusedGroup?.id || store.directLinkedGroupId();
const lastPaginationPage = useRef(1); const lastPaginationPage = useRef(1);
const [paginationPage, setPaginationPage] = useState(1); const [paginationPage, setPaginationPage] = useState(1);
...@@ -48,9 +55,9 @@ function NotebookView({ loadAnnotationsService }) { ...@@ -48,9 +55,9 @@ function NotebookView({ loadAnnotationsService }) {
// is changed within the sidebar and the Notebook re-opened, an entirely // is changed within the sidebar and the Notebook re-opened, an entirely
// new iFrame/app is created. This will need to be revisited. // new iFrame/app is created. This will need to be revisited.
store.setSortKey('Newest'); store.setSortKey('Newest');
if (focusedGroup) { if (groupId) {
loadAnnotationsService.load({ loadAnnotationsService.load({
groupId: focusedGroup.id, groupId,
maxResults: 5000, maxResults: 5000,
// Load annotations in reverse-chronological order because that is how // Load annotations in reverse-chronological order because that is how
...@@ -67,7 +74,7 @@ function NotebookView({ loadAnnotationsService }) { ...@@ -67,7 +74,7 @@ function NotebookView({ loadAnnotationsService }) {
sortOrder: 'desc', sortOrder: 'desc',
}); });
} }
}, [loadAnnotationsService, focusedGroup, store]); }, [loadAnnotationsService, groupId, store]);
// Pagination-page-changing callback // Pagination-page-changing callback
const onChangePage = newPage => { const onChangePage = newPage => {
......
...@@ -21,6 +21,7 @@ describe('NotebookView', () => { ...@@ -21,6 +21,7 @@ describe('NotebookView', () => {
fakeScrollIntoView = sinon.stub(); fakeScrollIntoView = sinon.stub();
fakeStore = { fakeStore = {
directLinkedGroupId: sinon.stub().returns(null),
focusedGroup: sinon.stub().returns({}), focusedGroup: sinon.stub().returns({}),
forcedVisibleThreads: sinon.stub().returns([]), forcedVisibleThreads: sinon.stub().returns([]),
getFilterValues: sinon.stub().returns({}), getFilterValues: sinon.stub().returns({}),
...@@ -64,6 +65,32 @@ describe('NotebookView', () => { ...@@ -64,6 +65,32 @@ describe('NotebookView', () => {
assert.calledWith(fakeStore.setSortKey, 'Newest'); assert.calledWith(fakeStore.setSortKey, 'Newest');
}); });
it('loads annotations for the direct-linked group if there is no focused group', () => {
fakeStore.focusedGroup.returns(null);
fakeStore.directLinkedGroupId.returns('direct123');
createComponent();
assert.calledWith(
fakeLoadAnnotationsService.load,
sinon.match({
groupId: 'direct123',
maxResults: 5000,
sortBy: 'updated',
sortOrder: 'desc',
})
);
});
it('does not load annotations if there is no focused or direct-linked group', () => {
fakeStore.focusedGroup.returns(null);
fakeStore.directLinkedGroupId.returns(null);
createComponent();
assert.notCalled(fakeLoadAnnotationsService.load);
});
it('renders the current group name', () => { it('renders the current group name', () => {
fakeStore.focusedGroup.returns({ id: 'hallothere', name: 'Hallo' }); fakeStore.focusedGroup.returns({ id: 'hallothere', name: 'Hallo' });
const wrapper = createComponent(); const wrapper = createComponent();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment