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.

Commits

Files

    Loading...