Skip to content

Commit

Permalink
Allow larger queries for user preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas committed Apr 11, 2024
1 parent d414aa6 commit 866ca99
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
13 changes: 12 additions & 1 deletion pkg/api/message/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const (
// maxRowsPerQuery defines the maximum number of rows we can return in a single query
maxRowsPerQuery = 100

// maxUserPreferencesRowsPerQuery sets a higher limit for querying the user preferences table
maxUserPreferencesRowsPerQuery = 500

// maxTopicsPerQueryRequest defines the maximum number of topics that can be queried in a single request.
// the number is likely to be more than we want it to be, but would be a safe place to put it -
// per Test_LargeQueryTesting, the request decoding already failing before it reaches th handler.
Expand Down Expand Up @@ -346,7 +349,7 @@ func (s *Service) Query(ctx context.Context, req *proto.QueryRequest) (*proto.Qu
}
}

if req.PagingInfo != nil && req.PagingInfo.Limit > maxRowsPerQuery {
if req.PagingInfo != nil && int(req.PagingInfo.Limit) > getMaxRows(req.ContentTopics[0]) {
return nil, status.Errorf(codes.InvalidArgument, "cannot exceed %d rows per query", maxRowsPerQuery)
}

Expand Down Expand Up @@ -395,3 +398,11 @@ func (s *Service) BatchQuery(ctx context.Context, req *proto.BatchQueryRequest)
Responses: responses,
}, nil
}

func getMaxRows(contentTopic string) int {
if topic.IsUserPreferences(contentTopic) {
return maxUserPreferencesRowsPerQuery
}

return maxRowsPerQuery
}
25 changes: 15 additions & 10 deletions pkg/topic/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import (
)

var topicCategoryByPrefix = map[string]string{
"test": "test",
"contact": "contact",
"intro": "v1-intro",
"dm": "v1-conversation",
"dmE": "v1-conversation-ephemeral",
"invite": "v2-invite",
"groupInvite": "v2-group-invite",
"m": "v2-conversation",
"mE": "v2-conversation-ephemeral",
"privatestore": "private",
"test": "test",
"contact": "contact",
"intro": "v1-intro",
"dm": "v1-conversation",
"dmE": "v1-conversation-ephemeral",
"invite": "v2-invite",
"groupInvite": "v2-group-invite",
"m": "v2-conversation",
"mE": "v2-conversation-ephemeral",
"privatestore": "private",
"userpreferences": "userpreferences",
}

func IsEphemeral(contentTopic string) bool {
return Category(contentTopic) == "v2-conversation-ephemeral" || Category(contentTopic) == "v1-conversation-ephemeral"
}

func IsUserPreferences(contentTopic string) bool {
return Category(contentTopic) == "userpreferences"
}

func Category(contentTopic string) string {
if strings.HasPrefix(contentTopic, "test-") {
return "test"
Expand Down

0 comments on commit 866ca99

Please sign in to comment.