Skip to content

Conversation

@Contentstack-AnkitaD
Copy link
Contributor

@Contentstack-AnkitaD Contentstack-AnkitaD commented Feb 16, 2025

workerB

Refactor the fetch.js file inorder to make debugging the sync token error more better and easy to understand.

@Contentstack-AnkitaD Contentstack-AnkitaD requested a review from a team as a code owner February 16, 2025 21:52
@Contentstack-AnkitaD Contentstack-AnkitaD changed the base branch from master to staging February 16, 2025 21:54
@Contentstack-AnkitaD Contentstack-AnkitaD requested review from a team and abhishek305 February 17, 2025 09:47
Copy link
Contributor

@abhishek305 abhishek305 left a comment

Choose a reason for hiding this comment

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

  • I would suggest just revisit the sync retry logic instead of refactoring the existing flow

Comment on lines +55 to +57
exports.setGlobalConfig = (config) => {
globalConfig = { ...config }; // Creates a new copy to avoid unintended mutations
};
Copy link
Contributor

Choose a reason for hiding this comment

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

what is globalConfig ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

globalConfig is just a way to store the config safely so we don’t accidentally modify the original object. It helps keep things consistent across different functions that need the same config values (like httpRetries for retries).
To prevent accidental overwrites, we use setGlobalConfig() to update it safely.
It was added to make sure we always use the correct config throughout the module.

Let me know if you think it could cause any issues.. @abhishek305

src/fetch.js Outdated
activity.end();

return { contentstackData };
return { contentstackData: syncData.data }
Copy link
Contributor

Choose a reason for hiding this comment

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

would this create an issue when accessing syncData as previously it was contentstackData.syncData ? now its changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great Catch, let me remove that possibility by restoring the data structure..

Comment on lines +199 to +205
const normalizeLimit = (limit) => {
if (limit > 100) {
console.error('Limit cannot exceed 100. Setting limit to 50.');
return 50;
}
return limit;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this limit ? and do we actually need to refactor that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a limitation that limit value cannot be set more than 100, incase user does that, we should by default send 50 to the api.
Hence normalizing the logic, incase we make any changes to this limitation, it will be easy to find and make any changes needed

@abhishek305
Copy link
Contributor

@Contentstack-AnkitaD lets close this PR and refactor the retry approach for synctoken

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.

5 participants