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

Mirror URL table's click column #1011

Merged
merged 7 commits into from
Dec 9, 2020
Merged

Mirror URL table's click column #1011

merged 7 commits into from
Dec 9, 2020

Conversation

yong-jie
Copy link
Member

@yong-jie yong-jie commented Dec 7, 2020

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.

  1. Deploy this PR that will let sequelize create a new url_clicks table.

  2. 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.

  3. Deploy a separate PR that changes application code to do read/writes to url_clicks table.

  4. Run a migration script to remove hooks and url table's click column.

Side effects of PR:

  • Original Clicks model renamed to DailyClicks.

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.

@yong-jie yong-jie marked this pull request as ready for review December 8, 2020 14:01
Copy link
Contributor

@liangyuanruo liangyuanruo left a comment

Choose a reason for hiding this comment

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

some suggestions but lgtm!

@yong-jie yong-jie merged commit 62b0777 into develop Dec 9, 2020
@yong-jie yong-jie deleted the url-click-table branch December 9, 2020 07:19
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