Speed up extension loading in tests by caching a URL.

Review Request #11313 — Created Dec. 1, 2020 and submitted

Information

Djblets
release-2.0.x

Reviewers

ExtensionManager.get_absolute_url() returns the URL pointing to the
extension manager UI, and to do this it uses a standard URL lookup.

However, there's a problem with this. When we initialize an extension,
we add any URLs it defines and we then flush the URL cache, requiring it
to be rebuilt for any new lookups. We do the same thing when we
uninitialize a URL.

In unit tests, we enable and disable extensions all the time, at least
once per test. This means that testing an extension with custom URLs or
an admin UI configuration or database page is terribly slow, as it's
constantly clearing, re-building, and clearing the cache.

Not all unit tests need the cache to be rebuilt. To avoid this,
get_absolute_url() now caches the result after the first lookup (since
the extension manager UI isn't going to be moving around).

This makes a huge difference. One extension's test suite dropped from 8
minutes to 2, just from this cached variable.

Unit tests passed.

Tested with a couple extensions and saw significant improvements to test
speed (averaging a 75% reduction in test time).

Summary ID
Speed up extension loading in tests by caching a URL.
`ExtensionManager.get_absolute_url()` returns the URL pointing to the extension manager UI, and to do this it uses a standard URL lookup. However, there's a problem with this. When we initialize an extension, we add any URLs it defines and we then flush the URL cache, requiring it to be rebuilt for any new lookups. We do the same thing when we uninitialize a URL. In unit tests, we enable and disable extensions all the time, at least once per test. This means that testing an extension with custom URLs or an admin UI configuration or database page is terribly slow, as it's constantly clearing, re-building, and clearing the cache. Not all unit tests need the cache to be rebuilt. To avoid this, `get_absolute_url()` now caches the result after the first lookup (since the extension manager UI isn't going to be moving around). This makes a huge difference. One extension's test suite dropped from 8 minutes to 2, just from this cached variable.
a7d76c6e377974a326507a56f829c989df1938d0
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-2.0.x (9f90841)