Skip to content

Return full item data instead of just ids option#1193

Draft
AbhilashVijayakumar wants to merge 13 commits intogorse-io:masterfrom
AbhilashVijayakumar:master
Draft

Return full item data instead of just ids option#1193
AbhilashVijayakumar wants to merge 13 commits intogorse-io:masterfrom
AbhilashVijayakumar:master

Conversation

@AbhilashVijayakumar
Copy link
Copy Markdown

@AbhilashVijayakumar AbhilashVijayakumar commented Mar 10, 2026

Currently after getting 10 ids to recommend to user, i need to make 10 calls to downstream system to get the meta data to show user a listing of the recommendations

if include-items query parameter is set, respond with full items instead of just ids so that additional call to downstream systems to show a list to user can be avoided & make integration more efficient.

Backward compatible as response will change only if the include-items new query parameter is set

…ust ids

if include-items query parameter respond with full items instead of just ids so that additional call to downstream systems to show a list to user can be avoided & make integration more efficient. Currently after getting 10 ids to recommend to user, i need to make 10 calls to downstream system to get the meta data to show user a listing of the recommendations
@AbhilashVijayakumar AbhilashVijayakumar changed the title return full item data instead of just ids Return full item data instead of just ids Mar 10, 2026
@AbhilashVijayakumar AbhilashVijayakumar changed the title Return full item data instead of just ids Return full item data instead of just ids option Mar 10, 2026
@AbhilashVijayakumar AbhilashVijayakumar marked this pull request as ready for review March 10, 2026 03:19
Comment thread server/rest.go Outdated
Comment thread server/rest.go Outdated
Comment thread server/rest.go Outdated
Comment thread server/rest.go Outdated
Comment thread server/rest.go Outdated

// RecommendResponse is the response for the recommend endpoint.
// It includes both item IDs (for backward compatibility) and full item data.
type RecommendResponse struct {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return array and remove structure to be compatible with no items situation

Comment thread server/rest.go Outdated

// ScoredItem is a scored item with optional full item data for X-Api-Version: 2.
type ScoredItem struct {
ItemId string `json:"ItemId"`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use id to be compatible with score

Comment thread server/rest.go
// Send result
if apiVersion == "2" {
Ok(response, scores)
if includeItems {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change variable names as well

Comment thread server/rest.go
itemIds := lo.Map(scores, func(item cache.Score, index int) string {
return item.Id
})
includeItems := request.QueryParameter("return-items") == "true"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move BatchGetItems to return item clause

Comment thread server/rest_test.go Outdated

// marshalRecommend builds the expected JSON for the recommend endpoint.
// It fetches full item data from the test DataClient and orders them to match itemIds.
func (suite *ServerTestSuite) marshalRecommend(itemIds []string) string {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to marshal scored items

Comment thread server/rest_test.go Outdated
// marshalRecommend builds the expected JSON for the recommend endpoint.
// It fetches full item data from the test DataClient and orders them to match itemIds.
func (suite *ServerTestSuite) marshalRecommend(itemIds []string) string {
ctx := context.Background()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use suite.T(). Context()

Comment thread server/rest.go Outdated
Writes([]string{}))
Param(ws.QueryParameter("return-items", "Include full item data in response").DataType("boolean")).
Returns(http.StatusOK, "OK", RecommendResponse{}).
Writes(RecommendResponse{}))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not change Writes

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 71.79487% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.68%. Comparing base (b507ecb) to head (40b0bea).

Files with missing lines Patch % Lines
server/rest.go 71.79% 9 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1193      +/-   ##
==========================================
- Coverage   72.72%   72.68%   -0.05%     
==========================================
  Files          88       88              
  Lines       16258    16289      +31     
==========================================
+ Hits        11824    11840      +16     
- Misses       3233     3246      +13     
- Partials     1201     1203       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AbhilashVijayakumar AbhilashVijayakumar marked this pull request as draft March 11, 2026 05:20
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