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

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

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.

Summary ID
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
Description From Last Updated

F841 local variable 'site_profile' is assigned to but never used

reviewbotreviewbot

F841 local variable 'site_profile' is assigned to but never used

reviewbotreviewbot

F811 redefinition of unused 'test_get_starred_review_groups_count' from line 451

reviewbotreviewbot

F811 redefinition of unused 'test_get_starred_review_groups_count_with_local_site' from line 469

reviewbotreviewbot

E999 SyntaxError: invalid syntax

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
chipx86
chipx86
Review request changed
Change Summary:
  • Added has_starred_review_groups(), has_starred_review_requests(), is_review_group_starred(), and is_review_request_starred().
  • Updated to make the local_site= arguments keyword-only arguments.
Summary:
[WIP] Add functions for querying and caching starred item counts for a user.
Add functions for querying and caching starred item counts for a user.
Description:
~  

This introduces Profile.get_starred_review_requests_count() and

~   Profile.get_starred_review_groups_count(), which return the number of
~   corresponding items starred by the user, either on a specific Local Site
  ~

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:

-   or on the global site.

   
~  

Most users don't star items, and likely don't star them very often. To

~   avoid unnecessary database queries, these counts are cached, making it
~   very quick to determine whether a user has starred review requests.

  ~
  • 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()
   
~  

The star/unstar methods will invalidate the cache count, recomputing the

~   next time the functions are called.

  ~

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.

   
~  

The plan will be to incorporate this into some query building, in order

~   to avoid unnecessary JOINs. This will take place in a future change.

  ~

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).

Commits:
Summary ID
Add functions for querying and caching starred item counts for a user.
This introduces `Profile.get_starred_review_requests_count()` and `Profile.get_starred_review_groups_count()`, which return the number of corresponding items starred by the user, either on a specific Local Site or on the global site. Most users don't star items, and likely don't star them very often. To avoid unnecessary database queries, these counts are cached, making it very quick to determine whether a user has starred review requests. The star/unstar methods will invalidate the cache count, recomputing the next time the functions are called. The plan will be to incorporate this into some query building, in order to avoid unnecessary JOINs. This will take place in a future change.
28e6b51431b8673f140ad7866393db9288cee14f
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

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.0.x (5677e8d)