Skip to content

Commit

Permalink
feat: Improve triggers query performances
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paultranvan committed Dec 11, 2024
1 parent 3385442 commit fc42acf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions src/components/Sections/SectionsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useAppsInMaintenance,
useClient,
useQuery,
useQueryAll,
useSettings
} from 'cozy-client'
import {
Expand Down Expand Up @@ -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[] }
Expand Down
10 changes: 8 additions & 2 deletions src/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
23 changes: 16 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6002,16 +6002,16 @@ [email protected]:
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"
Expand Down Expand Up @@ -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"

[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/cozy-tsconfig/-/cozy-tsconfig-1.2.0.tgz#17e61f960f139fae4d26cbac2254b9ab632b269e"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit fc42acf

Please sign in to comment.