8000 perf(timeline): reuse a person's For you affinity for a minute while their signals stay the same by adeelahmad · Pull Request #671 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

perf(timeline): reuse a person's For you affinity for a minute while their signals stay the same - #671

Merged
adeelahmad merged 1 commit into
mainfrom
claude/project-thread-pf8kii
Oct 19, 2026
Merged

adeelahmad merged 1 commit into
mainfrom
claude/project-thread-pf8kii

Conversation

@adeelahmad
Copy link
Copy Markdown
Owner

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.affinity keys 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests.
  • My change requires documentation updates, and I have updated docs/ accordingly.
  • Users need more than the title to understand it, so I wrote it as a fragment in changelog.d/ (timeline-for-you-cache.md).

Done questions (AGENTS.md)

  • Goal: fewer lookups per For you page with the same order; merged on green CI.
  • Agents: the same for them, through the API, MCP and the assistant.
  • Zero setup: works on its own.
  • Fewest clicks: n/a.
  • Configurable: n/a. It is an internal cache with no visible behaviour beyond a minute of staleness in the activities' own fields.
  • Light: less work per page; memory is bounded to 256 entries.
  • Private and secure: the key includes what the person may see, so nobody reuses another person's sum.
  • Cost: no model call.
  • User decides: n/a.
  • Upgrades: n/a, nothing stored.
  • Honest: docs/timeline.md says what is reused and for how long. Not measured: the time saved per page.
  • Tested and documented: pytest test_a_persons_affinity_is_reused_for_a_minute_until_a_signal_changes; docs, requirements.md and changelog.d are updated.
  • Open standards: n/a.
  • Reported: the result goes back in the thread.
  • Reuse: for_you.signals, events.get_many.

CI on the PR decides the merge.


Generated by Claude Code

…their signals stay the same

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ln25ykE6uBDqx21WBU94SX
@adeelahmad
adeelahmad merged commit 4ed9202 into main Oct 19, 2026
12 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-pf8kii branch October 19, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0