From fc42acf865d49b17dd87146bf40f707415e6bcdf Mon Sep 17 00:00:00 2001 From: Paul Tran-Van Date: Tue, 10 Dec 2024 15:43:05 +0100 Subject: [PATCH] feat: Improve triggers query performances We used to query all triggers, in order to determine which konnectors accounts are connected, to adapt display on the homepage. However, this query can be very time-consuming: it takes ~10s on an instance with 700+ triggers. This is due to the stack computing job information from each trigger. As we do not need such information here, we force the generic `/data` route, rather than the specialized `/jobs/triggers` route. --- package.json | 2 +- src/components/Sections/SectionsContext.tsx | 7 ++++--- src/queries.js | 10 +++++++-- yarn.lock | 23 ++++++++++++++------- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 420b3f3a2b..c3fa59ab0e 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "dependencies": { "@sentry/react": "7.119.0", "comlink": "4.4.1", - "cozy-client": "^51.0.0", + "cozy-client": "^51.6.0", "cozy-device-helper": "2.7.0", "cozy-devtools": "^1.2.1", "cozy-doctypes": "1.83.8", diff --git a/src/components/Sections/SectionsContext.tsx b/src/components/Sections/SectionsContext.tsx index 01b26f3ccc..6decb1c15a 100644 --- a/src/components/Sections/SectionsContext.tsx +++ b/src/components/Sections/SectionsContext.tsx @@ -13,6 +13,7 @@ import { useAppsInMaintenance, useClient, useQuery, + useQueryAll, useSettings } from 'cozy-client' import { @@ -85,17 +86,17 @@ export const SectionsProvider = ({ const client = useClient() const { t } = useI18n() - const { data: allTriggers } = useQuery( + const { data: allTriggers } = useQueryAll( _makeTriggersQuery.definition(), _makeTriggersQuery.options ) as { data: IOCozyTrigger[] } - const { data: accounts } = useQuery( + const { data: accounts } = useQueryAll( _makeAccountsQuery.definition(), _makeAccountsQuery.options ) as { data: IOCozyAccount[] } - const { data: konnectors } = useQuery( + const { data: konnectors } = useQueryAll( konnectorsConn.query, konnectorsConn ) as { data: IOCozyKonnector[] } diff --git a/src/queries.js b/src/queries.js index 1bdecae9ae..c59b1e320a 100644 --- a/src/queries.js +++ b/src/queries.js @@ -15,9 +15,15 @@ export const konnectorsConn = { } export const makeTriggersQuery = { - definition: () => Q('io.cozy.triggers'), + definition: () => { + return Q('io.cozy.triggers') + .partialIndex({ + worker: 'konnector' + }) + .limitBy(1000) + }, options: { - as: 'io.cozy.triggers', + as: 'io.cozy.triggers/worker=konnector', fetchPolicy: defaultFetchPolicy } } diff --git a/yarn.lock b/yarn.lock index d6667708e6..1bfc529387 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6002,16 +6002,16 @@ cozy-bi-auth@0.0.25: lodash "^4.17.20" node-jose "^1.1.4" -cozy-client@^51.0.0: - version "51.0.0" - resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-51.0.0.tgz#84b7f9c6a3c678791de7b06539af6595e0bb51c2" - integrity sha512-txbEkQFuZX1ZXi1/2bXLJK9SQR+sbZjjztIv3pt+g73veuVVz5wyDoJkMbLLf5dSiHARpHIWgIdBfX4prZwpWQ== +cozy-client@^51.6.0: + version "51.6.0" + resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-51.6.0.tgz#22f77a40f316011d8e8a298cc9d4cbc7cfdbbcc0" + integrity sha512-H0jhhju5jhoQHCiPZB2tfoRZb4QrhxfArNTRwLs5Lsd3+5WmtaSnPgbQUTBHWPRCv7qxP89Spz7eSgDmpdzA5Q== dependencies: "@cozy/minilog" "1.0.0" "@types/jest" "^26.0.20" "@types/lodash" "^4.14.170" btoa "^1.2.1" - cozy-stack-client "^51.0.0" + cozy-stack-client "^51.6.0" date-fns "2.29.3" json-stable-stringify "^1.0.1" lodash "^4.17.13" @@ -6310,6 +6310,15 @@ cozy-stack-client@^51.0.0: mime "^2.4.0" qs "^6.7.0" +cozy-stack-client@^51.6.0: + version "51.6.0" + resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-51.6.0.tgz#bd81605bdd1e68161d1143856f78bca969086575" + integrity sha512-MRBTKtBtQ6jnmS4ij+nYjgeOecSNr9Z9kCNDlKW9884JxnI4VGfpq1w+ihN3EVh3EyqD98vnaQZ8VuYr6czeVQ== + dependencies: + detect-node "^2.0.4" + mime "^2.4.0" + qs "^6.7.0" + cozy-tsconfig@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/cozy-tsconfig/-/cozy-tsconfig-1.2.0.tgz#17e61f960f139fae4d26cbac2254b9ab632b269e" @@ -12348,9 +12357,9 @@ msgpack5@^4.0.2: readable-stream "^2.3.6" safe-buffer "^5.1.2" -"mui-bottom-sheet@git+https://github.com/cozy/mui-bottom-sheet.git#v1.0.9": +"mui-bottom-sheet@https://github.com/cozy/mui-bottom-sheet.git#v1.0.9": version "1.0.8" - resolved "git+https://github.com/cozy/mui-bottom-sheet.git#3dc4c2a245ab39079bc2f73546bccf80847be14c" + resolved "https://github.com/cozy/mui-bottom-sheet.git#3dc4c2a245ab39079bc2f73546bccf80847be14c" dependencies: "@juggle/resize-observer" "^3.1.3" jest-environment-jsdom-sixteen "^1.0.3"