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 Rebuild counter cache #668

Merged
merged 3 commits into from
Jul 13, 2023
Merged

Conversation

kbrock
Copy link
Collaborator

@kbrock kbrock commented Jul 13, 2023

Alt to #665

Before

  • We were casting to a fixed length char field. Some records in the middle of the tree did not get an updated counter cache.
  • Mysql updated counter cache to nil if there were no children.

After

  • Using the conversion built into CONCAT, so no need to use CAST.
  • All implementations update counter cache to 0 when there are no children.
  • More robust tests for counter caches

kbrock and others added 2 commits July 12, 2023 23:57
Before
======

New records had the children counter cache value of nil.

On mysql, update_counter_cache sets nodes with no children to nil.

After
=====

New records have the children counter cache set to 0

On mysql, update_counter_cache now sets to 0 (was nil)
new records set the nodes with no children to have a count of 0.

Docs
====

Looks like there is no documentation for the child counter cache.
Need to add to the README\
Before
======

We were casting to a fixed length char field. This can truncate parts of the path

After
=====

Using the conversion built into concat, so no need to CAST.

MySQL works best with CHAR
Postgresql works better with VARCHAR
@RongRongTeng
Copy link
Contributor

🙏🏻

@kbrock kbrock merged commit 22c1991 into stefankroes:master Jul 13, 2023
8 checks passed
@kbrock kbrock deleted the rebuild-counter-cache branch July 13, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants