Skip to content

Commit

Permalink
fix(core): Make filter/sort query only hold onto node properties it n…
Browse files Browse the repository at this point in the history
…eeds (#34747)

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
  • Loading branch information
imjoshin and pieh committed Feb 15, 2022
1 parent 3c3362b commit 3df8583
Show file tree
Hide file tree
Showing 4 changed files with 398 additions and 176 deletions.
4 changes: 4 additions & 0 deletions benchmarks/memory/README.md
Expand Up @@ -38,6 +38,10 @@ A shorthand for start + connect.

Stop the container used for testing.

#### yarn docker:stats

Show a polling display of the container's docker stats.

### Gatsby

These commands are used for interfacing with gatsby.
Expand Down
36 changes: 26 additions & 10 deletions packages/gatsby/src/datastore/__tests__/run-fast-filters.js
Expand Up @@ -401,13 +401,15 @@ describe(`applyFastFilters`, () => {
const result = applyFastFilters(
createDbQueriesFromObject(filter),
[typeName],
new Map()
new Map(),
[],
[]
)
expect(Array.isArray(result)).toBe(true)
expect(result.length).toEqual(2)

result.map(node => {
expect(node.slog).toEqual(`def`)
expect(getNode(node.id).slog).toEqual(`def`)
})
})

Expand All @@ -419,13 +421,15 @@ describe(`applyFastFilters`, () => {
const result = applyFastFilters(
createDbQueriesFromObject(filter),
[typeName],
new Map()
new Map(),
[],
[]
)
expect(Array.isArray(result)).toBe(true)
expect(result.length).toEqual(2)

result.map(node => {
expect(node.deep.flat.search.chain).toEqual(300)
expect(getNode(node.id).deep.flat.search.chain).toEqual(300)
})
})

Expand All @@ -438,14 +442,16 @@ describe(`applyFastFilters`, () => {
const results = applyFastFilters(
createDbQueriesFromObject(filter),
[typeName],
new Map()
new Map(),
[],
[]
)

// Count is irrelevant as long as it is non-zero and they all match filter
expect(Array.isArray(results)).toBe(true)
expect(results.length).toEqual(1)
expect(results[0].slog).toEqual(`def`)
expect(results[0].deep.flat.search.chain).toEqual(300)
expect(getNode(results[0].id).slog).toEqual(`def`)
expect(getNode(results[0].id).deep.flat.search.chain).toEqual(300)
})

it(`supports elemMatch`, () => {
Expand All @@ -458,7 +464,9 @@ describe(`applyFastFilters`, () => {
const result = applyFastFilters(
createDbQueriesFromObject(filter),
[typeName],
new Map()
new Map(),
[],
[]
)

expect(result).not.toBe(undefined)
Expand All @@ -484,7 +492,9 @@ describe(`edge cases (yay)`, () => {
const result = applyFastFilters(
createDbQueriesFromObject(filter),
[typeName],
new Map()
new Map(),
[],
[]
)

// Sanity-check
Expand All @@ -511,7 +521,13 @@ describe(`edge cases (yay)`, () => {
await getDataStore().ready()

const run = () =>
applyFastFilters(createDbQueriesFromObject(filter), [typeName], new Map())
applyFastFilters(
createDbQueriesFromObject(filter),
[typeName],
new Map(),
[],
[]
)

expect(run).toThrow(
`Invariant violation: inconsistent node counters detected`
Expand Down

0 comments on commit 3df8583

Please sign in to comment.