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 16, 2024
1 parent 31f2564 commit 228127a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 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
19 changes: 14 additions & 5 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

0 comments on commit 228127a

Please sign in to comment.