feat: add topics endpoint for brand presence Data Insights table | LLMO-3605#1985
Merged
feat: add topics endpoint for brand presence Data Insights table | LLMO-3605#1985
Conversation
|
This PR will trigger a minor release when merged. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…MO-3605
Implements GET /org/:spaceCatId/brands/{all,:brandId}/brand-presence/topics
which powers the Data Insights table with topic-level aggregated data.
- Queries brand_presence_executions, deduplicates by prompt|region per topic
- Returns TopicDetail objects with PromptDetail items for expandable rows
- Supports pagination (page, pageSize), sorting (name, visibility, mentions,
citations, sentiment, popularity), and all existing filters
- Uses WEEKS_QUERY_LIMIT (200K) consistent with sentiment-overview
- Adds comprehensive unit tests for aggregateTopicData and createTopicsHandler
Made-with: Cursor
… UI expectations Sentiment was computed on a 0-1 scale (positive=1, neutral=0.5, negative=0) but the UI's formatSentimentFromScore expects 0-100. This caused all topics to display as "Negative". Changed to positive=100, neutral=50, negative=0 and return -1 for N/A. Popularity was returning raw imputed volume numbers (-10/-20/-30) but the UI expects categorical labels. Added volumeToCategory() to map averages back to High/Medium/Low/N/A. Made-with: Cursor
Covers uncovered branches in aggregateTopicData (null field fallbacks) and sortTopicDetails (unknown sortBy fallback, numeric sorting with zero/NaN values, null context.data in pagination params). Made-with: Cursor
…ies from prompt details | LLMO-3605 Separate the topics response into two endpoints for better performance: 1. /topics now returns topic-level summaries with `promptCount` instead of embedding the full `items[]` array, reducing initial payload size 2. New /topics/:topicId/prompts endpoint returns PromptDetail items for a single topic, loaded lazily when the user expands a topic row Also reduces default pageSize from 100 to 20 to support infinite scroll pagination in the UI. Made-with: Cursor
5088fb3 to
9e254d4
Compare
…ers endpoints Made-with: Cursor
…into feat/topics-endpoint-LLMO-3605
…edded resource - Count mentions/citations/sources from ALL execution rows per topic (not just the deduplicated latest), matching the original UI behavior - Use PostgREST embedded resource (brand_presence_sources(url_id)) to efficiently join source URLs instead of a separate batch query - Return sourceCount (unique source URLs) at the topic level for the "All Citations" column Made-with: Cursor
calvarezg
approved these changes
Mar 23, 2026
Contributor
calvarezg
left a comment
There was a problem hiding this comment.
Please address this before merging:
-
src/controllers/llmo/llmo-brand-presence.js(createTopicPromptsHandler) —decodeURIComponent(topicId)is called without a try-catch; a malformed percent-encodedtopicId(e.g.%GG) throws an uncaughtURIErrorresulting in a 500 instead of a 400 — wrap in try/catch and returnbadRequest('Invalid topic ID encoding'). -
docs/llmo-brandalf-apis/— No documentation added for the two new endpoints; all other brand presence endpoints have a corresponding.mddoc in this folder — add atopics-api.mdcovering query params, response shape (topicDetails,promptCount,sourceCount, pagination), and example requests/responses.
…docs - Wrap decodeURIComponent(topicId) in try-catch to return 400 instead of an uncaught URIError 500 for malformed percent-encoding - Add topics-api.md documenting both topics and topic-prompts endpoints Made-with: Cursor
solaris007
pushed a commit
that referenced
this pull request
Mar 23, 2026
# [1.365.0](v1.364.0...v1.365.0) (2026-03-23) ### Features * add topics endpoint for brand presence Data Insights table | LLMO-3605 ([#1985](#1985)) ([666b0bd](666b0bd))
Member
|
🎉 This PR is included in version 1.365.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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
Implements two endpoints for the Data Insights table in brand-presence-pg, splitting topic summaries from prompt details for better performance:
1.
GET /org/:spaceCatId/brands/{all,:brandId}/brand-presence/topics(updated)promptCountinstead of embedding the fullitems[]array, significantly reducing initial payload sizebrand_presence_executionsvia PostgREST, deduplicates byprompt|region_codewithin each topic, and aggregates intoTopicDetailobjectspage,pageSizedefault 20), sorting (name,visibility,mentions,citations,sentiment,popularity,position), and all existing filters (siteId,model/platform,categoryId,topicIds,region,origin)pageSizereduced from 100 to 20 to support infinite scroll pagination in the UI2.
GET /org/:spaceCatId/brands/{all,:brandId}/brand-presence/topics/:topicId/prompts(new)PromptDetailitems for a single topic, loaded lazily when the user expands a topic rowbuildPromptDetails()to deduplicate byprompt|region_codeand build prompt-level itemsWEEKS_QUERY_LIMIT(200K) cap consistent with other endpointsDesign Decisions
promptCountfor display), then lazily loads prompts on expansion.brand_presence_executionsquery (not thebrand_presence_topics_by_datematerialized view): The mat view lacksorganization_id,prompt,answer,urlcolumns needed for auth validation and PromptDetail items. Raw table approach is consistent with sentiment-overview.prompt|region_codewithin each topic: Matches original UI behavior, prevents count inflation whenbrands=all.answerfield excluded from SELECT to keep response size manageable.Related PRs
Test Plan
aggregateTopicData(updated: assertspromptCountinstead ofitems.length)buildPromptDetails(5 tests: correct building, deduplication, error handling, null fields)createTopicPromptsHandler(10 tests: bad request, forbidden, valid data, empty data, topic filtering, pagination, query errors, site validation, region/origin filters, brandId filtering)