Banzai::Filter::RedactorFilter is slow
When rendering the page for https://gitlab.com/gitlab-org/gitlab-ce/issues/4232 and gitlab-com/operations#42 (closed) about 400-500 ms is spent in
Banzai::Filter::RedactorFilter#call. That's almost half a second just to redact links in pre-rendered Markdown. If the Markdown itself has to be rendered first the time spent can be even greater.
This filter uses the various reference parser classes to determine what references a user can see. Most likely in certain cases these permission checks run a lot of heavy queries. Also, since this is a HTML pipeline filter it means it will process documents individually. This means that if you have 100 documents you need to run 100 times N queries in the worst case (where N is the number of queries needed for a single document).
As a start we should try to reduce the number of queries needed per document to an amount as small as possible.
The timings of this filter can be found at http://performance.gitlab.net/dashboard/db/markdown-filter-methods?var-process_type=rails&var-method=Banzai%3A%3AFilter%3A%3ARedactorFilter%23call.