Skip to content

Commit

Permalink
Merge branch 'master' into fix/path-bug
Browse files Browse the repository at this point in the history
* 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)
  ...
  • Loading branch information
moonmeister committed May 7, 2021
2 parents 84ef4b5 + 39f25b7 commit fc936ce
Show file tree
Hide file tree
Showing 326 changed files with 17,244 additions and 17,075 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ Licensed under the [MIT License](./LICENSE).
## 💜 Thanks
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.
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.
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.
6 changes: 3 additions & 3 deletions benchmarks/create-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"serve": "gatsby serve"
},
"dependencies": {
"gatsby": "^2.19.5",
"react": "^16.12.0",
"react-dom": "^16.12.0"
"gatsby": "^3.4.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"gatsby-plugin-benchmark-reporting": "*"
Expand Down
43 changes: 43 additions & 0 deletions benchmarks/query-filters-sort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Filters and sort benchmark

Stress tests various query filters (with and without sorting by random value).

# Usage

```shell
NUM_NODES=1000 NUM_PAGES=1000 FILTER=eq SORT=1 TEXT=1 yarn bench
```

Explanation:

- `FILTER`: one of `eq`, `gt`, `gt-lt`, `in`, `lt`, `ne`, `nin`, `regex`, `elemMatch-eq` (default: `eq`).
See `src/templates` for specific queries.
- `SORT`: when set, the benchmark will also add sorting to the query (by random integer value)
- `TEXT`: all nodes are lightweight by default (just 5 fields with numeric values or short strings).\
When settings this env variable - each node will get additional field with 4k of text
(useful for memory usage measurements)
- `NUM_NODES`: the number of nodes created (1000 by default)
- `NUM_PAGES`: the number of pages created (1000 by default, must be >= `NUM_NODES`)

# Example

Let's figure out time complexity of `gt` filter. To make this happen - let's run the benchmark
3 times with the same number of pages but growing number of nodes:

### run 1:

```shell
NUM_NODES=1000 FILTER=gt yarn bench
```

### run 2:

```shell
NUM_NODES=10000 FILTER=gt yarn bench
```

### run 3:

```shell
NUM_NODES=100000 FILTER=gt yarn bench
```
8 changes: 8 additions & 0 deletions benchmarks/query-filters-sort/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
siteMetadata: {
title: `Gatsby Benchmark Filters & Sort`,
description: `The filters and sort benchmark`,
author: `@gatsbyjs`,
},
// plugins: [`gatsby-plugin-benchmark-reporting`],
}
87 changes: 87 additions & 0 deletions benchmarks/query-filters-sort/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const NUM_PAGES = parseInt(process.env.NUM_PAGES || 1000, 10)
const NUM_NODES = parseInt(process.env.NUM_NODES || NUM_PAGES, 10)
const SORT = process.env.SORT
const FILTER = process.env.FILTER || `eq`
const TEXT = Boolean(process.env.TEXT)

if (NUM_NODES < NUM_PAGES) {
throw new Error("Expecting NUM_NODES >= NUM_PAGES")
}

const nodesPerPage = Math.max(1, Math.round(NUM_NODES / NUM_PAGES))
const ptop = require(`process-top`)()

exports.sourceNodes = async ({ actions: { createNode } }) => {
console.log(`Creating ${NUM_NODES} nodes`)
for (let nodeNum = 0; nodeNum < NUM_NODES; nodeNum++) {
const pageNum = Math.floor(nodeNum / nodesPerPage)
createNode({
id: String(nodeNum),
nodeNum,
pageNum,
nodeNumReversed: NUM_NODES - nodeNum,
testEq: String(nodeNum),
testIn: [`foo`, `bar`, `baz`, `foobar`][nodeNum % 4],
testElemMatch: [
{ testIn: [`foo`, `bar`, `baz`, `foobar`][nodeNum % 4] },
{ testEq: String(nodeNum) },
],
text: `${TEXT ? new Array(4128).join("*") : ``}${nodeNum}`,
sortRandom: Math.random() * NUM_NODES,
internal: {
type: `Test`,
contentDigest: String(nodeNum),
},
})
if (nodeNum % 50 === 0) {
await new Promise(resolve => setTimeout(resolve, 3))
}
}
if (global.gc) {
global.gc()
}
console.log(ptop.toString())
}

const pageTemplate = require.resolve(`./src/templates/${FILTER}.js`)
exports.createPages = async ({ actions: { createPage } }) => {
console.log(`Creating ${NUM_PAGES} pages for filter: ${FILTER}`)
for (let pageNum = 0; pageNum < NUM_PAGES; pageNum++) {
createPage({
path: `/path/${pageNum}/`,
component: pageTemplate,
context: {
pageNumAsStr: String(pageNum),
fooBarValues: [
[`foo`, `bar`, `baz`, `foobar`][pageNum % 4],
[`foo`, `bar`, `baz`, `foobar`][(pageNum + 1) % 4],
],
intValue: pageNum,
pageNum: pageNum,
pagesLeft: NUM_PAGES - pageNum,
limit: nodesPerPage,
skip: nodesPerPage * pageNum,
nodesTotal: NUM_NODES,
pagesTotal: NUM_PAGES,
sort: SORT
? { fields: ["sortRandom"], order: SORT === `1` ? `ASC` : `DESC` }
: undefined,
regex: `/^${String(pageNum).slice(0, 1)}/`, // node id starts with the same number as page id
},
})
if (pageNum % 50 === 0) {
await new Promise(resolve => setTimeout(resolve, 3))
}
}
if (global.gc) {
global.gc()
}
console.log(ptop.toString())
}

exports.onPostBuild = () => {
if (global.gc) {
global.gc()
}
console.log(ptop.toString())
}
21 changes: 21 additions & 0 deletions benchmarks/query-filters-sort/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "gatsby-starter-hello-world",
"description": "Gatsby hello world starter",
"license": "MIT",
"scripts": {
"bench": "gatsby clean && rimraf .data && node --max_old_space_size=16384 --expose-gc node_modules/gatsby/dist/bin/gatsby.js build",
"develop": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve"
},
"dependencies": {
"gatsby": "^3.4.1",
"process-top": "^1.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"rimraf": "^3.0.2"
},
"devDependencies": {
"gatsby-plugin-benchmark-reporting": "*"
}
}
3 changes: 3 additions & 0 deletions benchmarks/query-filters-sort/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from "react"

export default () => <div>Hello world!</div>
26 changes: 26 additions & 0 deletions benchmarks/query-filters-sort/src/templates/elemMatch-eq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react"
import { graphql } from "gatsby"

export default ({ data }) => {
if (!data?.allTest?.nodes) {
throw new Error("Wrong data")
}
return <div>{JSON.stringify(data)}</div>
}

export const query = graphql`
query($pageNumAsStr: String, $sort: TestSortInput) {
allTest(
filter: {
testElemMatch: { elemMatch: { testEq: { eq: $pageNumAsStr } } }
}
sort: $sort
limit: 5
) {
nodes {
nodeNum
text
}
}
}
`
20 changes: 20 additions & 0 deletions benchmarks/query-filters-sort/src/templates/eq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react"
import { graphql } from "gatsby"

export default ({ data }) => {
if (!data?.allTest?.nodes) {
throw new Error("Bad query result")
}
return <div>{JSON.stringify(data)}</div>
}

export const query = graphql`
query($pageNumAsStr: String!, $sort: TestSortInput) {
allTest(filter: { testEq: { eq: $pageNumAsStr } }, sort: $sort, limit: 5) {
nodes {
nodeNum
text
}
}
}
`
24 changes: 24 additions & 0 deletions benchmarks/query-filters-sort/src/templates/gt-lt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react"
import { graphql } from "gatsby"

export default ({ data }) => {
if (!data?.allTest?.nodes) {
throw new Error("Wrong data")
}
return <div>{JSON.stringify(data)}</div>
}

export const query = graphql`
query($pageNum: Int, $pagesTotal: Int, $sort: TestSortInput) {
allTest(
filter: { nodeNum: { gt: $pageNum, lt: $pagesTotal } }
sort: $sort
limit: 5
) {
nodes {
nodeNum
text
}
}
}
`
20 changes: 20 additions & 0 deletions benchmarks/query-filters-sort/src/templates/gt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react"
import { graphql } from "gatsby"

export default ({ data }) => {
if (!data?.allTest?.nodes) {
throw new Error("Wrong data")
}
return <div>{JSON.stringify(data)}</div>
}

export const query = graphql`
query($pagesLeft: Int, $sort: TestSortInput) {
allTest(filter: { nodeNum: { gt: $pagesLeft } }, sort: $sort, limit: 5) {
nodes {
nodeNum
text
}
}
}
`
20 changes: 20 additions & 0 deletions benchmarks/query-filters-sort/src/templates/in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react"
import { graphql } from "gatsby"

export default ({ data }) => {
if (!data?.allTest?.nodes?.length) {
throw new Error("Wrong data")
}
return <div>{JSON.stringify(data)}</div>
}

export const query = graphql`
query($fooBarValues: [String!], $sort: TestSortInput) {
allTest(filter: { testIn: { in: $fooBarValues } }, sort: $sort, limit: 5) {
nodes {
nodeNum
text
}
}
}
`
24 changes: 24 additions & 0 deletions benchmarks/query-filters-sort/src/templates/lt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react"
import { graphql } from "gatsby"

export default ({ data }) => {
if (!data?.allTest?.nodes) {
throw new Error("Wrong data")
}
return <div>{JSON.stringify(data)}</div>
}

export const query = graphql`
query($pageNum: Int, $sort: TestSortInput) {
allTest(
filter: { nodeNumReversed: { lt: $pageNum } }
sort: $sort
limit: 5
) {
nodes {
nodeNum
text
}
}
}
`
20 changes: 20 additions & 0 deletions benchmarks/query-filters-sort/src/templates/ne.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react"
import { graphql } from "gatsby"

export default ({ data }) => {
if (!data?.allTest?.nodes) {
throw new Error("Invalid data")
}
return <div>{JSON.stringify(data)}</div>
}

export const query = graphql`
query($pageNumAsStr: String!, $sort: TestSortInput) {
allTest(filter: { testEq: { ne: $pageNumAsStr } }, sort: $sort, limit: 5) {
nodes {
nodeNum
text
}
}
}
`
20 changes: 20 additions & 0 deletions benchmarks/query-filters-sort/src/templates/nin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react"
import { graphql } from "gatsby"

export default ({ data }) => {
if (!data?.allTest?.nodes) {
throw new Error("Invalid data")
}
return <div>{JSON.stringify(data)}</div>
}

export const query = graphql`
query($fooBarValues: [String!], $sort: TestSortInput) {
allTest(filter: { testIn: { nin: $fooBarValues } }, sort: $sort, limit: 5) {
nodes {
nodeNum
text
}
}
}
`
20 changes: 20 additions & 0 deletions benchmarks/query-filters-sort/src/templates/regex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react"
import { graphql } from "gatsby"

export default ({ data }) => {
if (!data?.allTest?.nodes?.length) {
throw new Error("Wrong data")
}
return <div>{JSON.stringify(data)}</div>
}

export const query = graphql`
query($regex: String, $sort: TestSortInput) {
allTest(filter: { id: { regex: $regex } }, sort: $sort, limit: 5) {
nodes {
nodeNum
text
}
}
}
`
Loading

0 comments on commit fc936ce

Please sign in to comment.