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

Conditionally preload data for optional fields #112

Open
Tracked by #155
juanca opened this issue Apr 3, 2018 · 1 comment
Open
Tracked by #155

Conditionally preload data for optional fields #112

juanca opened this issue Apr 3, 2018 · 1 comment

Comments

@juanca
Copy link
Contributor

juanca commented Apr 3, 2018

At the moment, I cannot figure out if there is a way to conditionally preload an association given a certain request. At the moment, custom_preload is invoked with the models and the requests associations.

I think it would be beneficial to also have access to the optional fields (are there other possibilities of bottlenecks?) in the custom_preload method to allow custom preloading. At the moment, I am preloading optional fields on every request which has an impact on memory used -- even when it is not necessary for a subset of requests.

Or better yet: a field and an association should provide a preload interface that can be automatically pooled to maximize usage of the preloader and minimize unnecessary memory usage.

@juanca
Copy link
Contributor Author

juanca commented Apr 3, 2018

Here is an example of declaring an optional field with a preload interface:

field :color_name, :string, 
  optional: true, 
  preload: :account_color, 
  dynamic: lambda { |workspace| workspace.account_color&.color&.name }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant