Skip to content

Commit

Permalink
feat(indexing): add skipIndexing flag (#99)
Browse files Browse the repository at this point in the history
* Add skipIndexing flag

* Add to README

* Update README.md

Co-authored-by: Haroen Viaene <hello@haroen.me>
Co-authored-by: Haroen Viaene <fingebimus@me.com>
  • Loading branch information
3 people authored Nov 7, 2020
1 parent 7372c70 commit e0965d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module.exports = {
enablePartialUpdates: true, // default: false
matchFields: ['slug', 'modified'], // Array<String> default: ['modified']
concurrentQueries: false, // default: true
skipIndexing: true, // default: false, useful for e.g. preview deploys or local development
},
},
],
Expand Down
15 changes: 14 additions & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,23 @@ function fetchAlgoliaObjects(index, attributesToRetrieve = ['modified']) {
}

exports.onPostBuild = async function ({ graphql }, config) {
const { appId, apiKey, queries, concurrentQueries = true } = config;
const {
appId,
apiKey,
queries,
concurrentQueries = true,
skipIndexing = false
} = config;

const activity = report.activityTimer(`index to Algolia`);
activity.start();

if (skipIndexing === true) {
setStatus(activity, `options.skipIndexing is true; skipping indexing`);
activity.end();
return;
}

const client = algoliasearch(appId, apiKey);

setStatus(activity, `${queries.length} queries to index`);
Expand Down Expand Up @@ -61,6 +73,7 @@ exports.onPostBuild = async function ({ graphql }, config) {
} catch (err) {
report.panic('failed to index to Algolia', err);
}

activity.end();
};

Expand Down

0 comments on commit e0965d7

Please sign in to comment.