Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cache): Store cache with sorted object keys #17607

Merged
merged 5 commits into from
Sep 4, 2022

Conversation

zharinov
Copy link
Collaborator

@zharinov zharinov commented Sep 4, 2022

Changes

Deep sort objects keys before JSON.stringify. This should help to avoid unnecessary disk writes of the essentially same data. Arrays are left unsorted as it may be unsafe.

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please tick one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@zharinov
Copy link
Collaborator Author

zharinov commented Sep 4, 2022

I've chosen sortobject over json-stable-sort since it's zero-dependency library and it was updated recently. Please object if you have a better choice.

Copy link
Collaborator

@Gabriel-Ladzaretti Gabriel-Ladzaretti left a comment

Choose a reason for hiding this comment

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

Ill just note that the prCahce issue is unrelated to the sorting problem of objects, although this sorting issue was also observed, so this is very welcome.

By looking at the source code for sortObject it seems that it does sort arrays as well.

https://github.com/bevry/sortobject/blob/f8202dc8735030fc82b6840e8cca80502aa3d694/source/index.ts#L53-L58

Otherwise, code LGTM.

EDIT: This indeed doesnt sort Arrays if no comparator function is provided.

@viceice viceice enabled auto-merge (squash) September 4, 2022 10:52
@viceice viceice merged commit 5dc1eb3 into renovatebot:main Sep 4, 2022
@viceice viceice deleted the fix/repo-cache-object-sort-order branch September 4, 2022 10:53
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 32.190.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prCache within repo cache is written while being out of date
4 participants