-
Notifications
You must be signed in to change notification settings - Fork 6
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
Allow to load associations asynchronously #26
base: main
Are you sure you want to change the base?
Conversation
e11f03b
to
ec5d51e
Compare
|
||
fixtures :companies, :accounts | ||
|
||
self.use_transactional_tests = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self. With the recent refactor in connection pool / pinned connections, we should actually be able to properly simulate async queries with transactional tests. We just need a lock around the connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@casperisfine We are interested in this - would we have to do anything in the tests themselves?
ec5d51e
to
f30028d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@byroot: two questions:
- I am assuming that the changes we will make to the production code will be of the form
<object>.association(:<associated_object>).async_load_target
, correct? - What will be the best way for us to get this change for testing in the Core code?
For now yes, this is just to test the internal capability, this isn't likely to be the final "end user API". It's more likely to be something like: post.load_async(:comments, tags, :author) I'm still thinking about it.
Depends what you need. If you just want to test locally or on CI, you can just edit the gem "rails", github: "rails/rails", branch: "main" by: gem "rails", github: "https://github.com/Shopify/rails/pull/26" |
9ecc9d2
to
6eb3d99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@casperisfine thanks for this! It LGTM. When do you intend to release this?
|
||
fixtures :companies, :accounts | ||
|
||
self.use_transactional_tests = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@casperisfine We are interested in this - would we have to do anything in the tests themselves?
first_firm = companies(:first_firm) | ||
|
||
promise = client.load_async(:firm) | ||
wait_for_async_query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to wait? Should not client.firm
wait already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to, it's only for testing purpose to ensure the query is actually executed in the background.
Opening here rather than upstream for now, because this is just exploratory work.
Notes:
belongs_to / has_one / has_many
is quite easy.:through
relations, but these are rare so not a priority.FYI: @hcmaATshopify @rafaelfranca