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 }) {
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 [paginationPage, setPaginationPage] = useState(1);
......@@ -48,9 +55,9 @@ function NotebookView({ loadAnnotationsService }) {
// is changed within the sidebar and the Notebook re-opened, an entirely
// new iFrame/app is created. This will need to be revisited.
store.setSortKey('Newest');
if (focusedGroup) {
if (groupId) {
loadAnnotationsService.load({
groupId: focusedGroup.id,
groupId,
maxResults: 5000,
// Load annotations in reverse-chronological order because that is how
......@@ -67,7 +74,7 @@ function NotebookView({ loadAnnotationsService }) {
sortOrder: 'desc',
});
}
}, [loadAnnotationsService, focusedGroup, store]);
}, [loadAnnotationsService, groupId, store]);
// Pagination-page-changing callback
const onChangePage = newPage => {
......
......@@ -21,6 +21,7 @@ describe('NotebookView', () => {
fakeScrollIntoView = sinon.stub();
fakeStore = {
directLinkedGroupId: sinon.stub().returns(null),
focusedGroup: sinon.stub().returns({}),
forcedVisibleThreads: sinon.stub().returns([]),
getFilterValues: sinon.stub().returns({}),
......@@ -64,6 +65,32 @@ describe('NotebookView', () => {
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', () => {
fakeStore.focusedGroup.returns({ id: 'hallothere', name: 'Hallo' });
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