-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[base] Optimize and move collate function to draft-utils (#1422)
This optimizes how we collate drafts and published into a single entry for display in document lists. Also moved the collate function into the common draftUtils package so that we can re-use it anywhere else it's needed. The numbers I got when collating a list of 10474 items locally (average of around 10 samples): *Before*: 142.15 ms *After*: 18.47 ms
- Loading branch information
Showing
3 changed files
with
44 additions
and
24 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {collate, removeDupes} from '../src/util/draftUtils' | ||
|
||
test('collate()', () => { | ||
const foo = {_id: 'foo'} | ||
const fooDraft = {_id: 'drafts.foo'} | ||
const barDraft = {_id: 'drafts.bar'} | ||
const baz = {_id: 'baz'} | ||
|
||
expect(collate([foo, fooDraft, barDraft, baz])).toEqual([ | ||
{id: 'foo', draft: fooDraft, published: foo}, | ||
{id: 'bar', draft: barDraft}, | ||
{id: 'baz', published: baz} | ||
]) | ||
}) | ||
|
||
test('removeDupes()', () => { | ||
const foo = {_id: 'foo'} | ||
const fooDraft = {_id: 'drafts.foo'} | ||
const barDraft = {_id: 'drafts.bar'} | ||
const baz = {_id: 'baz'} | ||
|
||
expect(removeDupes([foo, fooDraft, barDraft, baz])).toEqual([fooDraft, barDraft, baz]) | ||
}) |
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