-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sortable notification cache variants #39616
Conversation
644bb1b
to
ce085aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing anything in this PR that actually adds notifications to the cache. If I'm not mistaken this is only adding two new notification specific cache variants that will later consume notifications from the actual cache. Is that correct?
@rosstimothy Correct, notifications are added to the actual cache in this PR. I'll rename this PR to make it more clear. |
ce085aa
to
9bf270f
Compare
9bf270f
to
ac7d17a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with some minor efficiency/scalability nits.
7f9634e
to
cf73121
Compare
Purpose
Part of #37704
Adds notification
sortcache
s in order to be able to sort notifications by date from newest to oldest in a performant way.I recommend reviewing commit by commit.
Implementation
Two new
sortcache
s were added, aUserNotificationCache
for user-specific notifications (this contains all user-specific notifications for all users), and aGlobalNotificationCache
which contains all global notifications. I considered the option of having only one cache which contains all notifications (both user-specific and global) mixed together, however the drawback is that this wouldn't scale well with many users as it would mean that to fetch notifications for a user, we would need to iterate through possibly thousands of user-specific notifications for other users that are in the way.The cache implementation follows a similar pattern to
access_request_cache.go
, leveraging the recently addedsortcache
helper.The caches are sorted using their UUID's which means they will be already be lexicographically sorted by date. For user-specific notifications, the key is
<username>/<notification uuid>
, this is so that the notifications for a user will be grouped together when sorted.We return a stream as opposed to a list when fetching notifications because it's a convenient way for us to construct a page one item at a time while pulling from both user-specific notifications and global notifications. The
StreamXXXXNotifications()
methods work by fetching the entire relevant dataset from the cache upfront (sorted from newest to oldest) and then returning a stream which iterates through it.