Skip to content

Conversation

@vkalta
Copy link
Contributor

@vkalta vkalta commented Nov 26, 2021

Implements caching of last fetched content-types time, to reduce the subsequent build times.

@vkalta vkalta requested a review from a team November 26, 2021 06:23
@vkalta vkalta requested a review from a team as a code owner November 26, 2021 06:23
};
query.query.uid = {
$in: config.contentTypes
}; // const queryParams = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment if not required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

$in: referredContentTypesList
}
});
// query.query = JSON.stringify({ uid: { $in: referredContentTypesList } });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment if not required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};
query.query.uid = {
$nin: config.excludeContentTypes
}; // const queryParams = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment if not required

config.cdn = config.cdn ? config.cdn : 'https://cdn.contentstack.io/v3';
const typePrefix = config.type_prefix || 'Contentstack';

const lastFetchedTimeCacheKey = `${typePrefix.toLowerCase()}-content-type-fetch-time-${config.api_key}`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making your own key each time, what about a function that returns a key?

const getCacheKey = (name, config) => `${config.type_prefix ?? 'Contentstack'}-${name}-${config.api_key}`;

The benefit here is when you want to update the structure (for example i dont think api key is enough in a cache key, due to #117.) it's updated in a single place.


let lastFetchedTime = await cache.get(lastFetchedTimeCacheKey);
if (!lastFetchedTime) {
lastFetchedTime = (new Date(null)).toISOString();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why null here but empty on L69?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants