2021-11-04 10:29:24 +13:00
|
|
|
# Improving Compile Times
|
|
|
|
|
|
|
|
In previous versions of Ash, the standard way to configure the list of resources for an Api module looked like this:
|
|
|
|
|
|
|
|
```elixir
|
|
|
|
defmodule MyApp.MyApi do
|
|
|
|
use Ash.Api
|
|
|
|
|
|
|
|
|
|
|
|
resources do
|
|
|
|
resource MyApp.MyResource
|
|
|
|
...
|
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
This caused many compilation dependency issues, causing slow compile times when changing single files, and could also potentially lead to deadlocks.
|
|
|
|
|
|
|
|
The preferred way of doing this now looks like this:
|
|
|
|
|
|
|
|
```elixir
|
|
|
|
# Define a registry module
|
|
|
|
defmodule MyApp.MyApi.Registry do
|
|
|
|
use Ash.Registry,
|
|
|
|
extensions: Ash.Registry.ResourceValidations
|
|
|
|
|
2021-11-10 19:24:52 +13:00
|
|
|
entries do
|
2021-11-04 10:29:24 +13:00
|
|
|
entry MyApp.MyResource
|
|
|
|
...
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defmodule MyApp.MyApi do
|
|
|
|
use Ash.Api, otp_app: :my_app
|
|
|
|
end
|
|
|
|
|
|
|
|
# in `config/config.exs`
|
|
|
|
|
|
|
|
config :my_app, MyApp.MyApi,
|
2021-12-12 06:32:17 +13:00
|
|
|
resources: [
|
|
|
|
registry: MyApp.MyApi.Registry
|
|
|
|
]
|
2021-11-04 10:29:24 +13:00
|
|
|
```
|
|
|
|
|
2021-12-12 06:32:17 +13:00
|
|
|
This will prevent a bunch of cross-concern compile time dependencies, allowing for much faster compile times in general.
|