Skip to content

Commit

Permalink
chore(gatsby): count sift hits in telemetry (#23416)
Browse files Browse the repository at this point in the history
* chore(gatsby): count sift hits in telemetry

We want to know how frequent the fast indexes fail to find anything when they're actually supposed to find something. This is currently not tracked and leads to skewed results. By counting how frequent Sift finds something when fast indexes fail or bail, we can get more relevant insight into how well fast indexes are actually performing, and/or whether we need to start thinking about eliminating Sift altogether. tbd.

* Inverse if-order
  • Loading branch information
pvdz authored Apr 23, 2020
1 parent 7bc6af4 commit 2fe4071
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/gatsby/src/query/graphql-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface IGraphQLRunnerStats {
totalRunQuery: number
totalPluralRunQuery: number
totalIndexHits: number
totalSiftHits: number
totalNonSingleFilters: number
comparatorsUsed: Map<string, number>
uniqueFilterPaths: Set<string>
Expand All @@ -41,6 +42,7 @@ interface IGraphQLRunnerStatResults {
totalRunQuery: number
totalPluralRunQuery: number
totalIndexHits: number
totalSiftHits: number
totalNonSingleFilters: number
comparatorsUsed: Array<{ comparator: string; amount: number }>
uniqueFilterPaths: number
Expand Down Expand Up @@ -89,6 +91,7 @@ export default class GraphQLRunner {
totalRunQuery: 0,
totalPluralRunQuery: 0,
totalIndexHits: 0,
totalSiftHits: 0,
totalNonSingleFilters: 0,
comparatorsUsed: new Map(),
uniqueFilterPaths: new Set(),
Expand Down Expand Up @@ -141,6 +144,7 @@ export default class GraphQLRunner {
totalRunQuery: this.stats.totalRunQuery,
totalPluralRunQuery: this.stats.totalPluralRunQuery,
totalIndexHits: this.stats.totalIndexHits,
totalSiftHits: this.stats.totalSiftHits,
totalNonSingleFilters: this.stats.totalNonSingleFilters,
comparatorsUsed: comparatorsUsedObj,
uniqueFilterPaths: this.stats.uniqueFilterPaths.size,
Expand Down
15 changes: 14 additions & 1 deletion packages/gatsby/src/redux/run-sift.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,20 @@ const applyFilters = (
return result
}

return filterWithSift(filters, firstOnly, nodeTypeNames, resolvedFields)
const siftResult = filterWithSift(
filters,
firstOnly,
nodeTypeNames,
resolvedFields
)

if (stats) {
if (!siftResult || siftResult.length === 0) {
stats.totalSiftHits++
}
}

return siftResult
}

const filterToStats = (
Expand Down

0 comments on commit 2fe4071

Please sign in to comment.