Add cached statistics for LocalSites.

Review Request #12303 — Created May 26, 2022 and submitted — Latest diff uploaded

Information

Review Board
release-5.0.x

Reviewers

This introduces LocalSiteManager, which is the new manager for
LocalSite objects. It provides methods used to quickly make
determinations about the Local Site usage on the server.

The main method currently is get_stats(), which returns a dictionary
containing:

  1. The total number of Local Sites on the server
  2. The number of public Local Sites
  3. The number of private Local Sites
  4. A UUID representing the generated state (which can be used as a
    component of other cache keys to enable automatic invalidation)

This is cached and invalidated any time a LocalSite is created,
deleted, or if the public state has changed, making it fast and
reliable for lookups.

There are additional wrappers around this that leverage the cached
state. These include:

  • has_local_sites()
  • has_public_local_sites()
  • has_private_local_sites()

These will soon be used to make some parts of our queries conditional on
their presence, letting us simplify queries in the common case.

Unit tests pass.

Diff Revision 1

This is not the most recent revision of the diff. The latest diff is revision 3. See what's changed.

orig
1
2
3

Commits

First Last Summary ID Author
Add cached statistics for LocalSites.
This introduces `LocalSiteManager`, which is the new manager for `LocalSite` objects. It provides a `get_stat()` method that can be used to gather the counts on total, public, or private `LocalSite`s in the database. This is cached and invalidated any time a `LocalSite` is created, deleted, or if the `public` state has changed, making it fast and reliable for lookups. There are wrappers for quickly checking if there are any `LocalSite`s in the database at all, or if there are any public or private ones. These will soon be used to make some parts of our queries conditional on their presence, letting us simplify queries in the common case.
e86f6b911456247e0f0cc70841fd82a1507f4bb1 Christian Hammond
reviewboard/site/managers.py
reviewboard/site/models.py
reviewboard/site/signal_handlers.py
reviewboard/site/tests/test_local_site_manager.py
reviewboard/testing/testcase.py
Loading...