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

Fixes PLIN-2287 Improve Picard Filtering #80

Merged
merged 4 commits into from
Aug 6, 2019

Conversation

plusplusben
Copy link
Contributor

@plusplusben plusplusben commented Aug 5, 2019

  1. Adds FieldFilters to FilterRequests. Since FilterModels must be an actual instance of the struct being queried, we cannot add special filters like whereIn with a FilterModel. This PR adds FieldFilters to allow for more complex filters.

  2. Improve performance by using cached struct metadata instead of getting it on each iteration of a loop. This completely removes struct metadata gathering from the hydrate function, which was getting called for each record returned. If we can rely on the trace PDF that I saw in another ticket, I believe this should be helpful.

  3. Removes the ReflectTableInfo and GetPK functions in favor of previously existing functions.

@plusplusben plusplusben self-assigned this Aug 5, 2019
if filters != nil && len(filters) > 0 && modelVal != nil {
for _, filter := range filters {
fieldMetadata := filterMetadata.GetField(filter.FieldName)
tbl.AddWhere(fieldMetadata.GetColumnName(), filter.FilterValue)
Copy link
Contributor

@acofer acofer Aug 6, 2019

Choose a reason for hiding this comment

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

Does this still work if we have multiple filter values on the same field? The way I read the squirrel docs, it defaults to AND, so (assuming column name is id and filter.FilterValue is foo etc.) this will add WHERE id=foo AND id=bar AND id=baz, so we end up getting nothing back. That's why I added WHERE id IN (foo, bar, baz) instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

ands = append(ands, sq.Eq{

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, squirrel turns slices into Where Ins. The tests show it in action. This is from squirrel docs.
Screen Shot 2019-08-06 at 12 34 51 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, cool. Thanks for figuring this out.

@@ -63,6 +63,7 @@ func buildQuery(
modelVal *reflect.Value,
filters []qp.FieldFilter,
associations []tags.Association,
selectFields []string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Update docstring above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Copy link
Contributor

@acofer acofer left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for taking the time to circle back and clean up my quick fix.

@plusplusben plusplusben merged commit b679fe6 into master Aug 6, 2019
@plusplusben plusplusben deleted the PLIN-2287-improve-picard-filtering branch August 6, 2019 19:12
@ghost ghost unassigned plusplusben Oct 25, 2019
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