Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
As we are moving forward with features that require bulk database operations, we want to move click count (a frequently updated field) in the URL table.
This is because updating the click count atomically requires a row lock, and it is unlikely that bulk operations will be able to acquire the necessary locks to proceed if a link is being visited constantly.
Part 1 of #984
Solution
Visit our wiki page for in-depth discussion of solution.
Proposed migration approach involves multiple phases.
Deploy this PR that will let sequelize create a new
url_clicks
table.Run the migration script in this PR that will populate the
url_clicks
table, as well as create the necessary hooks to keep them always in sync.Deploy a separate PR that changes application code to do read/writes to
url_clicks
table.Run a migration script to remove hooks and
url
table's click column.Side effects of PR:
Clicks
model renamed toDailyClicks
.Deploy Notes
Deploy code first to let sequelize create the tables before running migration script.
New scripts:
20201207_synchronise_url_clicks.sql
: Copies click count into url_clicks table, and adds DB hooks to keep it in sync.