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 3 (Latest)

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 methods used to quickly make determinations about the Local Site usage on the server. The main method currently is `get_stat()`, 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.
4717d00788bf198b061063c6c8849c283f1dfcc1 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...