Skip to content

fix: eliminate redundant DB queries in get_learning_paths#119

Draft
cursor[bot] wants to merge 1 commit intofeat/learning-path-exemplarsfrom
cursor/learning-paths-performance-3caf
Draft

fix: eliminate redundant DB queries in get_learning_paths#119
cursor[bot] wants to merge 1 commit intofeat/learning-path-exemplarsfrom
cursor/learning-paths-performance-3caf

Conversation

@cursor
Copy link

@cursor cursor bot commented Mar 16, 2026

Problem

get_learning_paths called get_pattern_sharing as a black box but only used exemplar_sessions from the result. This duplicated four DB queries already performed by get_learning_paths (sessions, engineer names, facets, tool usages) and additionally computed patterns, bright spots, workflow profiles, and model costs — all discarded except the exemplar list. This effectively doubled the database load for the /learning-paths endpoint.

Solution

Extracted the pattern-building and exemplar-derivation logic from get_pattern_sharing into a shared _build_patterns_and_exemplars helper function. Both get_pattern_sharing and get_learning_paths now call this helper with pre-loaded data.

Changes to get_learning_paths:

  • Expanded its existing facets query to include extra columns needed for pattern building (outcome, agent_helpfulness, brief_summary)
  • Builds session_map, session_facets, session_tools, session_tool_count from data already being queried
  • Runs only 2 additional targeted queries (workflow profiles, model costs) that weren't previously available
  • Calls _build_patterns_and_exemplars directly instead of get_pattern_sharing

This eliminates 4 redundant DB queries (sessions, engineer names, facets, tool usages) and avoids all the discarded intermediate computation (pattern clustering, bright spots).

Testing

All 21 tests in tests/test_growth.py pass (learning paths, pattern sharing, and onboarding acceleration). Ruff lint and format checks pass.

Open in Web Open in Cursor 

…pre-loaded data

Extract pattern-building and exemplar-derivation logic from
get_pattern_sharing into a shared _build_patterns_and_exemplars helper.

get_learning_paths now:
- Expands its existing facets query to include extra columns needed for
  pattern building (outcome, agent_helpfulness, brief_summary)
- Builds session_map, session_facets, session_tools, session_tool_count
  from data already being queried
- Runs only 2 additional queries (workflow profiles, model costs)
- Calls _build_patterns_and_exemplars directly instead of
  get_pattern_sharing

This eliminates 4 redundant DB queries (sessions, engineer names, facets,
tool usages) that were previously re-executed by get_pattern_sharing.
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.

1 participant