Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(collection): avoid double update of some record by using the hash column as index #3304

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

Merged
merged 7 commits into from
Apr 11, 2025

Conversation

elevatebart
Copy link
Contributor

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

When two users on diferent parts of the world open the same un-deployed nuxt content powered website, they both trigger the deployment at the same time. Since it can take a moment for data to be synchronized, both can still be running the data at the same time, including the concatenation updates.

To avoid duplicating and therefore corrupting the data, I had the idea to use a temporary hash when inserting incomplete data:

example with the hash of the record being 123456798 and the column name content

INSERT INTO _col_collection VALUES ('52', '[values-slice-1...]', '123456798-50000')
UPDATE _col_collection SET content = CONCAT(content, '[values-slice-2]'), __hash__ = '123456798-100000' WHERE id = 52 AND __hash__ =  '123456798-50000'
UPDATE _col_collection SET content = CONCAT(content, '[values-slice-3]'), __hash__ = '123456798' WHERE id = 52 AND __hash__ =  '123456798-100000'

With this we prevent most corruption of data through multiple updates.
We still need a way to "repair" a system that has stopped deploying mid deployment.
But this should improve deployment stability slightly.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link
Member

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

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

Thanks, @elevatebart, for the PR; it's a nice fix.
Added two change requests before

Comment on lines -194 to -196
if (opts.hashColumn !== false) {
values.push(`'${valuesHash}'`)
}
Copy link
Member

Choose a reason for hiding this comment

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

We need to add back this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A system with no hashColumn would not benefit from this improvement.
I will set it up.

values.push(`'${valuesHash}'`)
}

const valuesWithHash = opts.hashColumn !== false ? [...values, `'${valuesHash}'`] : values
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking of removing hashColumn option and add it to all, it will simplify the logic here.

I added this option to avoid adding __hash__ to the development cache table, which causes SQL to fail. But forcing cache cleanup in the new version would be a better solution.

Copy link

pkg-pr-new bot commented Apr 10, 2025

npm i https://pkg.pr.new/@nuxt/content@3304

commit: f3cf756

Copy link
Member

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

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

Thanks ❀️

@farnabaz farnabaz merged commit ebfb6e5 into nuxt:main Apr 11, 2025
3 checks passed
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.

2 participants