Skip to content

fix: count iMessage handle frequency in SQL instead of loading 2,000 full rows - #6138

Merged
atomantic merged 1 commit into
atomantic:mainfrom
Bryandero98:fix/tribe-imports-handle-count-sql
Sep 4, 2026
Merged

fix: count iMessage handle frequency in SQL instead of loading 2,000 full rows#6138
atomantic merged 1 commit into
atomantic:mainfrom
Bryandero98:fix/tribe-imports-handle-count-sql

Conversation

@Bryandero98

Copy link
Copy Markdown
Contributor

Summary

  • suggestTribeImports() pulled up to 2,000 full human_activity_events rows (title, summary, participants + metadata JSONB) across the wire just to count metadata.handle occurrences in a Node Map.
  • Adds countEventsByHandle({ source, eventLimit }) to humanActivity.js: a GROUP BY aggregate over the same recency window that returns only { handle, eventCount } pairs, letting Postgres do the counting.
  • tribeContacts.suggestTribeImports() now calls the new aggregate and sums counts across raw handles that normalize to the same key (e.g. +15551234567 vs 5551234567), preserving the original frequency semantics.

Test plan

  • server/services/humanActivity.db.test.js — new countEventsByHandle suite: groups/counts per handle, excludes events with no handle, empty-source case. Could not run locally (no Postgres in this dev environment); gated to run via npm run test:db in CI same as the rest of the file.
  • npx vitest run services/humanActivity.test.js services/tribeContacts.test.js routes/contacts.test.js — all green, no regressions.
  • biome lint clean on both changed files.

Closes #6026

🤖 Generated with Claude Code

…full rows

suggestTribeImports() pulled up to 2,000 full human_activity_events rows
(participants + metadata JSONB, title, summary) across the wire just to
count occurrences of metadata.handle in a Node Map. Adds
countEventsByHandle(), a GROUP BY aggregate that returns only handle +
count, and switches suggestTribeImports() to it.

Refs atomantic#6026
@atomantic
atomantic merged commit b3381ea into atomantic:main Sep 4, 2026
7 checks passed
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.

suggestTribeImports loads 2,000 full event rows with JSONB to compute handle frequency in Node memory

2 participants