-
Notifications
You must be signed in to change notification settings - Fork 464
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
find and fix corrupted children counts #584
Comments
Something like this ? We didn't implement it as not yet had the need, so can't guarantee it's solid. (inspired by Ancestry::ClassMethods.rebuild_depth_cache!)
|
The best way to do this is probably via a single sql query This is probably not valid sql, but will hopefully get you close: Direct descendents: UPDATE #{table_name}
SET child_count = (
select count(*)
from table_name children
where children.ancestry =
case when #{table_name}.ancestry is null then #{table_name}.id::varchar
else #{table_name}.ancestry || '/' || #{table_name}.id::varchar
end
) Probably wouldn't be that hard to get into a method. For all child decedents, we'd need to include both the |
@denodster I'm digging into what may be causing this. So that I may mimic your environment as closely as possible:
Any anything else you can think of that may help reproduce would be great. I'll also be adding:
@ptorrsmith If you could share similar information, that would be great, too. (so I can take that into account when looking into better support for dependant_count_cache.) |
@denodster would you possibly be running mysql? |
We have a rather large database, and one of our clients wrote in about a bug that we determined to be a result of children_count being wrong for many many users ( we aren't really sure how many) Is there something I can do to regenerate all children counts in our database?
The text was updated successfully, but these errors were encountered: