Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add limit to GetTimeline query #375

Merged
merged 2 commits into from
Sep 12, 2023
Merged

Conversation

wesbillman
Copy link
Collaborator

No description provided.

@@ -151,6 +152,7 @@ message TimelineQuery {
}

repeated Filter filters = 1;
int32 limit = 2;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried making this optional but for some reason, it was always nil even if I passed it in a GetTimeline request from the console. I couldn't figure out how to resolve that so I removed the optionality. Not sure what's up there.

Comment on lines 256 to 258
if limit != nil {
q += fmt.Sprintf(" LIMIT %d", *limit)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this the right approach to this? I mostly needed limit for pagination. I could also add a Filter but it seemed like it might be more clear and outside of the filter flow, but curious what you think @alecthomas

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks fine to me, except for the use of *int

// Get 1 more than the requested limit to determine if there are more results.
limitPlusOne := limit + 1

results, err := c.dal.QueryEvents(ctx, &limitPlusOne, query...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a types.Option or just an int where 0 is treated as missing

@@ -180,7 +180,7 @@ type eventRow struct {
RequestKey types.Option[model.IngressRequestKey]
}

func (d *DAL) QueryEvents(ctx context.Context, filters ...EventFilter) ([]Event, error) {
func (d *DAL) QueryEvents(ctx context.Context, limit *int, filters ...EventFilter) ([]Event, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, if this truly is optional, it should just be a filter function like all the others.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok maybe I'll just go that route then. I wasn't sure if there was a common pattern here I should follow but it sounds like Filters might be the way to go

@wesbillman wesbillman merged commit deddbd8 into main Sep 12, 2023
@wesbillman wesbillman deleted the add-limit-to-get-timeline branch September 12, 2023 01:56
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