-
Notifications
You must be signed in to change notification settings - Fork 32
chore: refactor findOneComplete to avoid dup #2236
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
base: master
Are you sure you want to change the base?
Conversation
17e2257
to
c0cb71d
Compare
66439f5
to
46f029c
Compare
Looks good to me! Great to avoid duplicated functionality. (However, I don't fully understand the consequences of your type changes, so I'll let someone else approve) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All type changes look good, but I had a couple questions (see below).
This also conflicts with fixes to findOneComplete
in #2212 so we need to pick an approach
}, | ||
}, | ||
include: ["all"], | ||
fields: ["datasetName", "pid"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the fields projection as a valid queryFilter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test (as the other) was wrong. It does not make sense to ask for these fields and then expect different fiedls to be present in the response IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HayenNico The 'fields' filter is still present, as tested in other tests (eg 0207). It's used by findAllComplete
, so it doesn't need special treatment in findOneComplete
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should keep this test though to document how fields
interacts with includes
. I guess the previous test was trying to show that the fields
property only applied to dataset fields, and is overridden by includes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think this test case should stay in. It is true that the test doesn't work as expected for fields
based on the current master branch, since the lookup was done differently in findOneComplete
and findAllComplete
(different ordering in aggregation pipeline, definitely a bug). This part was adressed in #2212, so at least the fixes for tests from that PR should be carried over to here.
src/datasets/datasets.service.ts
Outdated
pipeline.push({ $skip: limits.skip || 0 }); | ||
|
||
pipeline.push({ $limit: limits.limit || 10 }); | ||
if (limits?.limit) pipeline.push({ $limit: limits.limit }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the default changes the behavior in an edge case for the /api/v4/datasets
(former fullquery) endpoint, when queryFilter.limits
exists but does not include queryFilter.limits.limit
. Before the response would always be limited to 10 datasets, with this the response could have arbitrarily many datasets.
I'm not opposed to the change, but then we should be consistent about not assuming default filters
In principle my PR (a part from the defaults use case that I'll address) only reuses findAllComplete in findOneComplete. This avoids duplication and is conceptually more consistent I think as findOneComplete is just a special case of the findAllComplete. I also think is more intuitive for the user that the 2 endpoints work the same. The difference was only the order of the project stage, which in findOne was applied before the relation, thus I had to change the test. I think for a user this would not make sense. If I ask for the "instrument" relation and then don't include "instrument" in the fields it is expected I believe "instruments" will not be there. So I would lean towards my PR (a bit biased :) ), as a start and then apply the changes from #2212 as I added in the comment there |
If the findOneComplete query can be done with the findAllComplete query, I don’t see why we need it at all. |
it's just a utility that sets the filters and this allows me not to change where findOneComplete was historically used. I am not sure why this was ever implemented, but if you follow the old logic (or check the changes of this PR), it does exactly the same. BTW the add Since it's a findOne and not findById, it does not set the ID. I agree the findById could reuse this. When reading the code, I think it would be way easier if for every controller, for the GETs we had essentially 1 function in service reused in all controllers, i.e. this findAllComplete with |
I'm on board with this refactor, but I think at least part of #2212 (the bugfix for @nitrosx @Junjiequan @abdimo101 Do you think it would be better to split #2212 into two PRs, one for the |
@HayenNico @nitrosx @abdimo101 I think it's better to merge the PR with bug fix (use correct lookup sequence for all controllers), add corresponding tests and then open an issue to discuss enhanced include logic later on |
Description
Avoids logic duplication and reuses existing more generic function
Changes:
Tests included
Documentation
official documentation info