gatsby-source-wordpress
Version:
Source data from WordPress in an efficient and scalable way.
32 lines (30 loc) • 1.17 kB
JavaScript
;
exports.__esModule = true;
exports.persistPreviouslyCachedImages = void 0;
var _store = require("../store");
var _getGatsbyApi = require("../utils/get-gatsby-api");
var _cache = require("../utils/cache");
var _gatsbyFeatures = require("../utils/gatsby-features");
const persistPreviouslyCachedImages = async () => {
const {
helpers,
pluginOptions
} = (0, _getGatsbyApi.getGatsbyApi)();
// get all existing media item nodes
const mediaItemNodes = helpers.getNodesByType(`${pluginOptions.schema.typePrefix}MediaItem`);
if (_gatsbyFeatures.needToTouchNodes) {
// and if needed touch them so they aren't garbage collected.
// we will remove them as needed when receiving DELETE events from WP
mediaItemNodes.forEach(node => helpers.actions.touchNode(node));
}
const imageNodeMetaByUrl = await (0, _cache.getPersistentCache)({
key: `image-node-meta-by-url`
});
if (imageNodeMetaByUrl) {
(0, _store.getStore)().dispatch.imageNodes.setState({
nodeMetaByUrl: imageNodeMetaByUrl
});
}
};
exports.persistPreviouslyCachedImages = persistPreviouslyCachedImages;
//# sourceMappingURL=persist-cached-images.js.map