Skip to content

Commit fc936ce

Browse files
committed
Merge branch 'master' into fix/path-bug
* master: (45 commits) chore(release): Publish next pre-minor fix(gatsby-source-shopify): fix linting (gatsbyjs#31291) fix(deps): update minor and patch for gatsby-plugin-preact (gatsbyjs#31169) chore: add gatsby-plugin-gatsby-cloud to renovate chore: update renovatebot config to support more packages (gatsbyjs#31289) chore(deps): update dependency @types/semver to ^7.3.5 (gatsbyjs#31148) fix(deps): update minor and patch for gatsby-plugin-manifest (gatsbyjs#31160) fix(deps): update minor and patch for gatsby-remark-copy-linked-files (gatsbyjs#31163) fix(deps): update dependency mini-css-extract-plugin to v1.6.0 (gatsbyjs#31158) chore(deps): update dependency @testing-library/react to ^11.2.6 (gatsbyjs#31168) docs(gatsby-source-shopify): Updates Shopify README with new plugin info (gatsbyjs#31287) chore: run yarn deduplicate (gatsbyjs#31285) docs(gatsby-plugin-image): Add docs for customizing default options (gatsbyjs#30344) fix(gatsby-plugin-image): print error details (gatsbyjs#30417) chore(docs): Update "Adding Search with Algolia" guide (gatsbyjs#29460) chore(docs): Update MDX frontmatter for programmatic pages (gatsbyjs#29798) docs: Add image plugin architecture doc (gatsbyjs#31096) perf(gatsby): use fastq instead of better-queue + refactor (gatsbyjs#31269) feat(gatsby-plugin-image): Export ImageDataLike type (gatsbyjs#30590) fix(gatsby): update plugin api types (gatsbyjs#30819) ...
2 parents 84ef4b5 + 39f25b7 commit fc936ce

File tree

326 files changed

+17244
-17075
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

326 files changed

+17244
-17075
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,6 @@ Licensed under the [MIT License](./LICENSE).
175175

176176
## 💜 Thanks
177177

178-
Thanks goes out to all our many contributors creating plugins, starters, videos, and blog posts. And a special appreciation for our community members helping with issues and PRs, or answering questions on Discord and GitHub Discussions.
178+
Thanks go out to all our many contributors creating plugins, starters, videos, and blog posts. And a special appreciation for our community members helping with issues and PRs, or answering questions on Discord and GitHub Discussions.
179179

180180
A big part of what makes Gatsby great is each and every one of you in the community. Your contributions enrich the Gatsby experience and make it better every day.

benchmarks/create-pages/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"serve": "gatsby serve"
1010
},
1111
"dependencies": {
12-
"gatsby": "^2.19.5",
13-
"react": "^16.12.0",
14-
"react-dom": "^16.12.0"
12+
"gatsby": "^3.4.0",
13+
"react": "^17.0.2",
14+
"react-dom": "^17.0.2"
1515
},
1616
"devDependencies": {
1717
"gatsby-plugin-benchmark-reporting": "*"
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Filters and sort benchmark
2+
3+
Stress tests various query filters (with and without sorting by random value).
4+
5+
# Usage
6+
7+
```shell
8+
NUM_NODES=1000 NUM_PAGES=1000 FILTER=eq SORT=1 TEXT=1 yarn bench
9+
```
10+
11+
Explanation:
12+
13+
- `FILTER`: one of `eq`, `gt`, `gt-lt`, `in`, `lt`, `ne`, `nin`, `regex`, `elemMatch-eq` (default: `eq`).
14+
See `src/templates` for specific queries.
15+
- `SORT`: when set, the benchmark will also add sorting to the query (by random integer value)
16+
- `TEXT`: all nodes are lightweight by default (just 5 fields with numeric values or short strings).\
17+
When settings this env variable - each node will get additional field with 4k of text
18+
(useful for memory usage measurements)
19+
- `NUM_NODES`: the number of nodes created (1000 by default)
20+
- `NUM_PAGES`: the number of pages created (1000 by default, must be >= `NUM_NODES`)
21+
22+
# Example
23+
24+
Let's figure out time complexity of `gt` filter. To make this happen - let's run the benchmark
25+
3 times with the same number of pages but growing number of nodes:
26+
27+
### run 1:
28+
29+
```shell
30+
NUM_NODES=1000 FILTER=gt yarn bench
31+
```
32+
33+
### run 2:
34+
35+
```shell
36+
NUM_NODES=10000 FILTER=gt yarn bench
37+
```
38+
39+
### run 3:
40+
41+
```shell
42+
NUM_NODES=100000 FILTER=gt yarn bench
43+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
siteMetadata: {
3+
title: `Gatsby Benchmark Filters & Sort`,
4+
description: `The filters and sort benchmark`,
5+
author: `@gatsbyjs`,
6+
},
7+
// plugins: [`gatsby-plugin-benchmark-reporting`],
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const NUM_PAGES = parseInt(process.env.NUM_PAGES || 1000, 10)
2+
const NUM_NODES = parseInt(process.env.NUM_NODES || NUM_PAGES, 10)
3+
const SORT = process.env.SORT
4+
const FILTER = process.env.FILTER || `eq`
5+
const TEXT = Boolean(process.env.TEXT)
6+
7+
if (NUM_NODES < NUM_PAGES) {
8+
throw new Error("Expecting NUM_NODES >= NUM_PAGES")
9+
}
10+
11+
const nodesPerPage = Math.max(1, Math.round(NUM_NODES / NUM_PAGES))
12+
const ptop = require(`process-top`)()
13+
14+
exports.sourceNodes = async ({ actions: { createNode } }) => {
15+
console.log(`Creating ${NUM_NODES} nodes`)
16+
for (let nodeNum = 0; nodeNum < NUM_NODES; nodeNum++) {
17+
const pageNum = Math.floor(nodeNum / nodesPerPage)
18+
createNode({
19+
id: String(nodeNum),
20+
nodeNum,
21+
pageNum,
22+
nodeNumReversed: NUM_NODES - nodeNum,
23+
testEq: String(nodeNum),
24+
testIn: [`foo`, `bar`, `baz`, `foobar`][nodeNum % 4],
25+
testElemMatch: [
26+
{ testIn: [`foo`, `bar`, `baz`, `foobar`][nodeNum % 4] },
27+
{ testEq: String(nodeNum) },
28+
],
29+
text: `${TEXT ? new Array(4128).join("*") : ``}${nodeNum}`,
30+
sortRandom: Math.random() * NUM_NODES,
31+
internal: {
32+
type: `Test`,
33+
contentDigest: String(nodeNum),
34+
},
35+
})
36+
if (nodeNum % 50 === 0) {
37+
await new Promise(resolve => setTimeout(resolve, 3))
38+
}
39+
}
40+
if (global.gc) {
41+
global.gc()
42+
}
43+
console.log(ptop.toString())
44+
}
45+
46+
const pageTemplate = require.resolve(`./src/templates/${FILTER}.js`)
47+
exports.createPages = async ({ actions: { createPage } }) => {
48+
console.log(`Creating ${NUM_PAGES} pages for filter: ${FILTER}`)
49+
for (let pageNum = 0; pageNum < NUM_PAGES; pageNum++) {
50+
createPage({
51+
path: `/path/${pageNum}/`,
52+
component: pageTemplate,
53+
context: {
54+
pageNumAsStr: String(pageNum),
55+
fooBarValues: [
56+
[`foo`, `bar`, `baz`, `foobar`][pageNum % 4],
57+
[`foo`, `bar`, `baz`, `foobar`][(pageNum + 1) % 4],
58+
],
59+
intValue: pageNum,
60+
pageNum: pageNum,
61+
pagesLeft: NUM_PAGES - pageNum,
62+
limit: nodesPerPage,
63+
skip: nodesPerPage * pageNum,
64+
nodesTotal: NUM_NODES,
65+
pagesTotal: NUM_PAGES,
66+
sort: SORT
67+
? { fields: ["sortRandom"], order: SORT === `1` ? `ASC` : `DESC` }
68+
: undefined,
69+
regex: `/^${String(pageNum).slice(0, 1)}/`, // node id starts with the same number as page id
70+
},
71+
})
72+
if (pageNum % 50 === 0) {
73+
await new Promise(resolve => setTimeout(resolve, 3))
74+
}
75+
}
76+
if (global.gc) {
77+
global.gc()
78+
}
79+
console.log(ptop.toString())
80+
}
81+
82+
exports.onPostBuild = () => {
83+
if (global.gc) {
84+
global.gc()
85+
}
86+
console.log(ptop.toString())
87+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "gatsby-starter-hello-world",
3+
"description": "Gatsby hello world starter",
4+
"license": "MIT",
5+
"scripts": {
6+
"bench": "gatsby clean && rimraf .data && node --max_old_space_size=16384 --expose-gc node_modules/gatsby/dist/bin/gatsby.js build",
7+
"develop": "gatsby develop",
8+
"build": "gatsby build",
9+
"serve": "gatsby serve"
10+
},
11+
"dependencies": {
12+
"gatsby": "^3.4.1",
13+
"process-top": "^1.2.0",
14+
"react": "^17.0.2",
15+
"react-dom": "^17.0.2",
16+
"rimraf": "^3.0.2"
17+
},
18+
"devDependencies": {
19+
"gatsby-plugin-benchmark-reporting": "*"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import React from "react"
2+
3+
export default () => <div>Hello world!</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default ({ data }) => {
5+
if (!data?.allTest?.nodes) {
6+
throw new Error("Wrong data")
7+
}
8+
return <div>{JSON.stringify(data)}</div>
9+
}
10+
11+
export const query = graphql`
12+
query($pageNumAsStr: String, $sort: TestSortInput) {
13+
allTest(
14+
filter: {
15+
testElemMatch: { elemMatch: { testEq: { eq: $pageNumAsStr } } }
16+
}
17+
sort: $sort
18+
limit: 5
19+
) {
20+
nodes {
21+
nodeNum
22+
text
23+
}
24+
}
25+
}
26+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default ({ data }) => {
5+
if (!data?.allTest?.nodes) {
6+
throw new Error("Bad query result")
7+
}
8+
return <div>{JSON.stringify(data)}</div>
9+
}
10+
11+
export const query = graphql`
12+
query($pageNumAsStr: String!, $sort: TestSortInput) {
13+
allTest(filter: { testEq: { eq: $pageNumAsStr } }, sort: $sort, limit: 5) {
14+
nodes {
15+
nodeNum
16+
text
17+
}
18+
}
19+
}
20+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default ({ data }) => {
5+
if (!data?.allTest?.nodes) {
6+
throw new Error("Wrong data")
7+
}
8+
return <div>{JSON.stringify(data)}</div>
9+
}
10+
11+
export const query = graphql`
12+
query($pageNum: Int, $pagesTotal: Int, $sort: TestSortInput) {
13+
allTest(
14+
filter: { nodeNum: { gt: $pageNum, lt: $pagesTotal } }
15+
sort: $sort
16+
limit: 5
17+
) {
18+
nodes {
19+
nodeNum
20+
text
21+
}
22+
}
23+
}
24+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default ({ data }) => {
5+
if (!data?.allTest?.nodes) {
6+
throw new Error("Wrong data")
7+
}
8+
return <div>{JSON.stringify(data)}</div>
9+
}
10+
11+
export const query = graphql`
12+
query($pagesLeft: Int, $sort: TestSortInput) {
13+
allTest(filter: { nodeNum: { gt: $pagesLeft } }, sort: $sort, limit: 5) {
14+
nodes {
15+
nodeNum
16+
text
17+
}
18+
}
19+
}
20+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default ({ data }) => {
5+
if (!data?.allTest?.nodes?.length) {
6+
throw new Error("Wrong data")
7+
}
8+
return <div>{JSON.stringify(data)}</div>
9+
}
10+
11+
export const query = graphql`
12+
query($fooBarValues: [String!], $sort: TestSortInput) {
13+
allTest(filter: { testIn: { in: $fooBarValues } }, sort: $sort, limit: 5) {
14+
nodes {
15+
nodeNum
16+
text
17+
}
18+
}
19+
}
20+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default ({ data }) => {
5+
if (!data?.allTest?.nodes) {
6+
throw new Error("Wrong data")
7+
}
8+
return <div>{JSON.stringify(data)}</div>
9+
}
10+
11+
export const query = graphql`
12+
query($pageNum: Int, $sort: TestSortInput) {
13+
allTest(
14+
filter: { nodeNumReversed: { lt: $pageNum } }
15+
sort: $sort
16+
limit: 5
17+
) {
18+
nodes {
19+
nodeNum
20+
text
21+
}
22+
}
23+
}
24+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default ({ data }) => {
5+
if (!data?.allTest?.nodes) {
6+
throw new Error("Invalid data")
7+
}
8+
return <div>{JSON.stringify(data)}</div>
9+
}
10+
11+
export const query = graphql`
12+
query($pageNumAsStr: String!, $sort: TestSortInput) {
13+
allTest(filter: { testEq: { ne: $pageNumAsStr } }, sort: $sort, limit: 5) {
14+
nodes {
15+
nodeNum
16+
text
17+
}
18+
}
19+
}
20+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default ({ data }) => {
5+
if (!data?.allTest?.nodes) {
6+
throw new Error("Invalid data")
7+
}
8+
return <div>{JSON.stringify(data)}</div>
9+
}
10+
11+
export const query = graphql`
12+
query($fooBarValues: [String!], $sort: TestSortInput) {
13+
allTest(filter: { testIn: { nin: $fooBarValues } }, sort: $sort, limit: 5) {
14+
nodes {
15+
nodeNum
16+
text
17+
}
18+
}
19+
}
20+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default ({ data }) => {
5+
if (!data?.allTest?.nodes?.length) {
6+
throw new Error("Wrong data")
7+
}
8+
return <div>{JSON.stringify(data)}</div>
9+
}
10+
11+
export const query = graphql`
12+
query($regex: String, $sort: TestSortInput) {
13+
allTest(filter: { id: { regex: $regex } }, sort: $sort, limit: 5) {
14+
nodes {
15+
nodeNum
16+
text
17+
}
18+
}
19+
}
20+
`

0 commit comments

Comments
 (0)