Add functions for querying and caching starred item counts for a user.
Review Request #12025 — Created Feb. 2, 2022 and submitted
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 |
---|---|
5e2ffabf6ad82c2fe1da5acf6ccaa8f93afd5ba5 |
Description | From | Last Updated |
---|---|---|
F841 local variable 'site_profile' is assigned to but never used |
reviewbot | |
F841 local variable 'site_profile' is assigned to but never used |
reviewbot | |
F811 redefinition of unused 'test_get_starred_review_groups_count' from line 451 |
reviewbot | |
F811 redefinition of unused 'test_get_starred_review_groups_count_with_local_site' from line 469 |
reviewbot | |
E999 SyntaxError: invalid syntax |
reviewbot |
- Change Summary:
-
- Updated for Review Board 5.
- Removed backwards-compatibility code intended for maintaining compatibility for a backport that never happened.
- Fixed duplicate test method names.
- Removed unused variables.
- Commits:
-
Summary ID eccc83e321e96c86607481d15573f60f22c0824c 28e6b51431b8673f140ad7866393db9288cee14f - Branch:
-
release-4.0.xrelease-5.0.x
Checks run (2 succeeded)
- Change Summary:
-
- Added
has_starred_review_groups()
,has_starred_review_requests()
,is_review_group_starred()
, andis_review_request_starred()
. - Updated to make the
local_site=
arguments keyword-only arguments.
- Added
- 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()
andis_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 28e6b51431b8673f140ad7866393db9288cee14f 5e2ffabf6ad82c2fe1da5acf6ccaa8f93afd5ba5