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 ActiveRecord::ConnectionAdapters::QueryCache#dirties_query_cache #41147

Conversation

OuYangJinTing
Copy link
Contributor

@OuYangJinTing OuYangJinTing commented Jan 17, 2021

Summary

In the active_record/connection_adapters/abstract/database_statements.rb file, #create method is alias of #insert method.
In the active_record/connection_adapters/abstract/query_cache.rb file, #create method is not cleanup query cache.
We should override #create method cleanup query cache too.


assert_equal count + 1, Event.count
ensure
Event.find(1)&.destroy
Copy link
Member

Choose a reason for hiding this comment

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

Can you use reset_fixtures("posts") and Post model instead?

Suggested change
Event.find(1)&.destroy
reset_fixtures("posts")

https://buildkite.com/rails/rails/builds/74129#3b2b1120-8262-4d6a-87b4-d6649ee9155d/1070-1079

Copy link
Member

Choose a reason for hiding this comment

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

Or, use the returning value for create (id = @connection.create(...)).

Suggested change
Event.find(1)&.destroy
Event.find(id).destroy if id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@connection.enable_query_cache!

count = Event.count
binds = [[Event.column_for_attribute("id"), 1]]
Copy link
Member

Choose a reason for hiding this comment

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

Don't use the deprecated legacy binds (an array of [column || nil, value]).

https://buildkite.com/rails/rails/builds/74129#f336c8d3-da13-4408-8e86-cedecdabba7d/1066-1075

Suggested change
binds = [[Event.column_for_attribute("id"), 1]]
binds = [1]

@OuYangJinTing OuYangJinTing force-pushed the fix_query_cache_is_dirty_after_perform_created branch 2 times, most recently from f2d018d to 6162ce3 Compare January 17, 2021 12:11
Comment on lines 449 to 450
binds = ["", ""]
bind_param = Arel::Nodes::BindParam.new(nil)
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove unused variables?

Suggested change
binds = ["", ""]
bind_param = Arel::Nodes::BindParam.new(nil)

https://github.com/rails/rails/pull/41147/checks?check_run_id=1716707664

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@OuYangJinTing OuYangJinTing force-pushed the fix_query_cache_is_dirty_after_perform_created branch from 6162ce3 to 79d5712 Compare January 17, 2021 12:59
@OuYangJinTing
Copy link
Contributor Author

@kamipo Thank you for your review and suggestions.

@kamipo kamipo merged commit f54a15e into rails:main Jan 17, 2021
@kamipo
Copy link
Member

kamipo commented Jan 17, 2021

Thanks!

kamipo added a commit that referenced this pull request Feb 1, 2021
…_after_perform_created

Fix ActiveRecord::ConnectionAdapters::QueryCache#dirties_query_cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants