Enhancement: speed up merge document list retrieval

This commit is contained in:
shamoon 2024-04-19 10:04:10 -07:00
parent 4392628bd7
commit a47d36f5e5
3 changed files with 25 additions and 11 deletions

View File

@ -36,14 +36,18 @@ describe('MergeConfirmDialogComponent', () => {
{ id: 2, name: 'Document 2' }, { id: 2, name: 'Document 2' },
{ id: 3, name: 'Document 3' }, { id: 3, name: 'Document 3' },
] ]
jest.spyOn(documentService, 'getCachedMany').mockReturnValue(of(documents)) jest.spyOn(documentService, 'getFew').mockReturnValue(
of({
all: documents.map((d) => d.id),
count: documents.length,
results: documents,
})
)
component.ngOnInit() component.ngOnInit()
expect(component.documents).toEqual(documents) expect(component.documents).toEqual(documents)
expect(documentService.getCachedMany).toHaveBeenCalledWith( expect(documentService.getFew).toHaveBeenCalledWith(component.documentIDs)
component.documentIDs
)
}) })
it('should move documentIDs on drop', () => { it('should move documentIDs on drop', () => {
@ -64,7 +68,13 @@ describe('MergeConfirmDialogComponent', () => {
{ id: 2, name: 'Document 2' }, { id: 2, name: 'Document 2' },
{ id: 3, name: 'Document 3' }, { id: 3, name: 'Document 3' },
] ]
jest.spyOn(documentService, 'getCachedMany').mockReturnValue(of(documents)) jest.spyOn(documentService, 'getFew').mockReturnValue(
of({
all: documents.map((d) => d.id),
count: documents.length,
results: documents,
})
)
component.ngOnInit() component.ngOnInit()

View File

@ -34,10 +34,10 @@ export class MergeConfirmDialogComponent
ngOnInit() { ngOnInit() {
this.documentService this.documentService
.getCachedMany(this.documentIDs) .getFew(this.documentIDs)
.pipe(takeUntil(this.unsubscribeNotifier)) .pipe(takeUntil(this.unsubscribeNotifier))
.subscribe((documents) => { .subscribe((r) => {
this._documents = documents this._documents = r.results
}) })
} }

View File

@ -866,9 +866,13 @@ describe('BulkEditorComponent', () => {
jest jest
.spyOn(documentListViewService, 'documents', 'get') .spyOn(documentListViewService, 'documents', 'get')
.mockReturnValue([{ id: 3 }, { id: 4 }]) .mockReturnValue([{ id: 3 }, { id: 4 }])
jest jest.spyOn(documentService, 'getFew').mockReturnValue(
.spyOn(documentService, 'getCachedMany') of({
.mockReturnValue(of([{ id: 3 }, { id: 4 }])) all: [3, 4],
count: 2,
results: [{ id: 3 }, { id: 4 }],
})
)
jest jest
.spyOn(documentListViewService, 'selected', 'get') .spyOn(documentListViewService, 'selected', 'get')
.mockReturnValue(new Set([3, 4])) .mockReturnValue(new Set([3, 4]))