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

refactor: unify preload_defaults functions #316

Closed

Conversation

noaccOS
Copy link
Contributor

@noaccOS noaccOS commented Jul 3, 2023

Provide a global Repo.preload_defaults to load default preloads for a given module, instead of using a distinct function for each one.

Repo.preload_defaults's logic is to make modules define their own default_preloads/0 function, and use its return value as Repo.preload/3's second parameter.

A follow up pr might define a behaviour for the default_preloads/0 function, but this might reside in an external library and it is unclear to me whether it provides significant advantages.

Edit: now depends on #322

Edit: Repo.preload_defaults_in_result is provided for ease of use after
a fetch/update/insert method.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 894d4e38192a06b731613d1fae22a141bbb47b72-PR-316

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 13 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.1%) to 82.382%

Files with Coverage Reduction New Missed Lines %
lib/edgehog/update_campaigns/target.ex 1 33.33%
lib/edgehog/devices.ex 6 94.55%
lib/edgehog/update_campaigns.ex 6 92.11%
Totals Coverage Status
Change from base Build 97a0b562a307f5d81164707e3a39901d06025b42: 0.1%
Covered Lines: 1155
Relevant Lines: 1402

💛 - Coveralls

@noaccOS noaccOS force-pushed the default-preload-behavior branch 6 times, most recently from bb375d2 to a58425f Compare July 11, 2023 14:12
they work like get functions but always return a tuple {:ok, item} or
{:error, :not_found}

Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
Provide a global `Repo.preload_defaults` to load default preloads for a
given module, instead of using a distinct function for each one.

`Repo.preload_defaults`'s logic is to make modules define their own
`default_preloads/0` function, and use its return value as
`Repo.preload/3`'s second parameter.

`Repo.preload_defaults_in_result` is provided for ease of use after
a fetch/update/insert method.

Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants