Repository navigation
perf(timeline): reuse a person's For you affinity for a minute while their signals stay the same - #671
Merged
Conversation
…their signals stay the same Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ln25ykE6uBDqx21WBU94SX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Adeel · project thread
Description
Before: each For you page summed the person's affinity again. Each time it looked up every activity their recent signals were on, up to 800 ids across the sources. That happened on every page, every Older and every poll.
After: the signals are still read on every page, since those are small indexed queries. The summed affinity is reused for 60 seconds while the person, the namespaces they may see and their signals are all the same. A new reaction, comment, mark or open changes the signals, so it shows at once. After the minute the sum is made again, because the activities it was built from may have changed. The cache holds at most 256 people per process, and the oldest entry goes first.
How:
for_you.affinitykeys a module cache on (account, admin, spaces) and compares the stored signal list. The lookup moved to_sum. The test fixtures clear the cache with each new database.Motivation and Context
This is a refine-later item of the activity stream design: "could cache each person's affinity for a minute rather than summing it on every read". It keeps For you light on a Pi.
Types of changes
!in the title)Checklist:
make hookschecks it on commit).docs/accordingly.changelog.d/(timeline-for-you-cache.md).Done questions (AGENTS.md)
test_a_persons_affinity_is_reused_for_a_minute_until_a_signal_changes; docs, requirements.md and changelog.d are updated.for_you.signals,events.get_many.CI on the PR decides the merge.
Generated by Claude Code