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: Do not query /jobs/triggers with a partialFilter #1571

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cozy-stack-client/src/TriggerCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class TriggerCollection extends DocumentCollection {
*/
async find(selector = {}, options = {}) {
const { worker, type, ...rest } = selector
const hasOnlyWorkerAndType = Object.keys(rest).length === 0
const hasOnlyWorkerAndType =
Object.keys(rest).length === 0 && !options.partialFilter
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: hasOnlyWorkerAndType is not accurate anymore

Copy link
Contributor Author

@paultranvan paultranvan Dec 10, 2024

Choose a reason for hiding this comment

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

Hmm I don't think so, hasOnlyWorkerAndType is true if there is no other keys than worker and type in selector and NO partialFilter.
Reversely, if there is another key or a partialFilter, hasOnlyWorkerAndType is false

Copy link
Contributor

@zatteo zatteo Dec 10, 2024

Choose a reason for hiding this comment

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

and NO partialFilter that part made me think that it is not accurate anymore.

Is it possible that there is no worker and type in selector but a partial filter is present ?

edit: oh they are linked together, so it can not happen ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible that there is no worker and type in selector but a partial filter is present ?

Yes it can. And in this case, hasOnlyWorkerAndType is false, as there is a partialFilter

if (hasOnlyWorkerAndType) {
// @see https://github.com/cozy/cozy-stack/blob/master/docs/jobs.md#get-jobstriggers
const url = `/jobs/triggers?${buildParamsUrl(worker, type)}`
Expand Down
14 changes: 14 additions & 0 deletions packages/cozy-stack-client/src/TriggerCollection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ describe('TriggerCollection', () => {
}
)
})

it('should call /data/io.cozy.triggers/_find route if partialFilter is passed', async () => {
stackClient.fetchJSON.mockReturnValue(FIND_RESPONSE_FIXTURES)
await collection.find({}, { partialFilter: { worker: 'konnector' } })
expect(stackClient.fetchJSON).toHaveBeenLastCalledWith(
'POST',
'/data/io.cozy.triggers/_find',
{
selector: { worker: 'konnector' },
skip: 0,
use_index: '_design/by__filter_(worker_konnector)'
}
)
})
})

describe('destroy', () => {
Expand Down
Loading