Add functions for querying and caching starred item counts for a user.

Review Request #12025 — Created Feb. 2, 2022 and submitted — Latest diff uploaded

Information

Review Board
release-5.0.x

Reviewers

This introduces new functions to Profile for querying starred review
request and group information in a way that leverages a cache. The
following functions have been added:

  • get_starred_review_groups_count()
  • get_starred_review_requests_count()
  • has_starred_review_groups()
  • has_starred_review_requests()
  • is_review_group_starred()
  • is_review_request_starred()

Both get_starred_review_groups_count() and
get_starred_review_requests_count() return the number of starred
groups/review requests for a given user and optional LocalSite. These
values are cached, making subsequent lookups fast, and enabling
decisions to be made based on the content.

These are wrapped by has_starred_review_groups() and
has_starred_review_requests(), which fetch the count and return whether
there's at least 1 item.

is_review_group_starred() and is_review_request_starred() return
whether a given review group or review request are starred. This queries
the database as normal, but if the user hasn't starred any items of the
given type, this won't perform a query at all.

The star/unstar methods will invalidate the cache count.

Most users don't star items, and likely don't star them very often. By
caching, we can avoid a lot of lookups and simplify database queries for
users (which will be implemented in another change).

Unit tests pass.

Diff Revision 3 (Latest)

orig
1
2
3

Commits

First Last Summary ID Author
Add functions for querying and caching starred item counts for a user.
This introduces new functions to `Profile` for querying starred review request and group information in a way that leverages a cache. The following functions have been added: * `get_starred_review_groups_count()` * `get_starred_review_requests_count()` * `has_starred_review_groups()` * `has_starred_review_requests()` * `is_review_group_starred()` * `is_review_request_starred()` Both `get_starred_review_groups_count() and get_starred_review_requests_count()` return the number of starred groups/review requests for a given user and optional `LocalSite`. These values are cached, making subsequent lookups fast, and enabling decisions to be made based on the content. These are wrapped by `has_starred_review_groups()` and has_starred_review_requests()`, which fetch the count and return whether there's at least 1 item. `is_review_group_starred()` and `is_review_request_starred()` return whether a given review group or review request are starred. This queries the database as normal, but if the user hasn't starred any items of the given type, this won't perform a query at all. The star/unstar methods will invalidate the cache count. Most users don't star items, and likely don't star them very often. By caching, we can avoid a lot of lookups and simplify database queries for users (which will be implemented in another change).
5e2ffabf6ad82c2fe1da5acf6ccaa8f93afd5ba5 Christian Hammond
reviewboard/accounts/models.py
reviewboard/accounts/tests/test_profile.py
Loading...