Upgrading Discourse to Zeitwerk

I made some progress around Zeitwerk, however, I changed my approach. My original plan was to change every place where Discourse is not following the Zeitwerk filename convention. After a few fixes, I realised that this is just the tip of the iceberg and noticed that if I am going to follow that path, then pull request will be difficult to read and confidently merge to master. For example, all job classes under regular directory should have Regular namespace, same with Onceoff and Scheduled.

I decided to step back a little bit and think about a more evolutionary approach than revolutionary.

I decided that it would be better to introduce custom Inflector, which will cover all files which are not following Zeitwerk convention. The biggest benefit will be that we would be able to deploy that small change and once we are happy with Zeitwerk and we don’t have any performance downgrades, we can start fixing convention file by file in reasonable small pull requests.

I found some problems which could not be sorted by custom Inflector, so I made additional fixes to make it work.

Pull request is still in progress, however, at this stage, I can run Discourse with Zeitwerk and default plugins, run all specs and run benchmark without a problem.

I wanted first to be at that stable state when all specs are passing. Now I can confidently start removing all require_dependency one by one and also test official plugins. Once everything is ready, I will share with you benchmark results in this post.

For now, if you are interested in progress you may take a look on that draft PR - https://github.com/discourse/discourse/pull/8098

The most important file is that custom Zeitwerk Inflector - https://github.com/discourse/discourse/pull/8098/files#diff-1d11f8dea7245fa4921be68dbc40a1d1

10 Likes