fix: count iMessage handle frequency in SQL instead of loading 2,000 full rows - #6138
Merged
atomantic merged 1 commit intoSep 4, 2026
Merged
Conversation
…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
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.
Summary
suggestTribeImports()pulled up to 2,000 fullhuman_activity_eventsrows (title, summary,participants+metadataJSONB) across the wire just to countmetadata.handleoccurrences in a NodeMap.countEventsByHandle({ source, eventLimit })tohumanActivity.js: aGROUP BYaggregate 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.+15551234567vs5551234567), preserving the original frequency semantics.Test plan
server/services/humanActivity.db.test.js— newcountEventsByHandlesuite: 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 vianpm run test:dbin 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 lintclean on both changed files.Closes #6026
🤖 Generated with Claude Code