Recompilation speedup: fix AnnounceValidator compile-dep on Endpoint
In ActivityPub, threads are joined together by a "context" ID. AnnounceValidator wants to autogenerate a context ID for objects if one isn't found.
Pleroma's context IDs are local URLs, so we need Endpoint.url/0
to generate one. Unfortunately, it will have to be a compile-time dep, because Ecto's field/3
is a macro. And of course Endpoint depends back on AnnounceValidator, so we have a cycle.
For starters, I decided to make ObjectValidators.ContextID
its own Ecto field type. Since ObjectValidators.ObjectID
already exists, this seems like a natural progression. The autogenerate code is moved there.
But, we still have a compile-dep on Endpoint. Pleroma is an ActivityPub implementation, and thus depends heavily on Endpoint.url/0
(for ActivityPub IDs) in every part of the code, even inside Ecto fields. To prevent cycles, we need some way to get the URL without Endpoint
.
Ultimately Endpoint.url/0
just pulls data out of the application config, and we can do the same. So I created Pleroma.Config.url/0
to do just that. I know we just changed "two ways to get URLs" in !3432 (merged), but I think this addition is justified by the fact Pleroma needs to depend so heavily on Endpoint.url/0
, especially in scenarios where compile-deps can't be avoided.
Alternatively, if you don't like this solution, I found a way to achieve the same result in a simpler way (but it's slightly hacky): develop...cycles-validator
Gets rid of the biggest cycle, bringing us down to 5: https://www.diffchecker.com/qdv2wre1