cardano-graphql
cardano-graphql copied to clipboard
Slow _or queries
Individually it takes milliseconds, but together it takes a few seconds. How can it be solved?
query getTransactions {
transactions_aggregate(
where: {
_or: [
{ outputs: { address: { _in: ["addr1q9acqkgp6ah0xl6dt6gxtrmj8ee4ehnzfeq9rcuwrldalfsl94rky7hgymnt04zzmn696ksga7526ycypga0p0q5scfquhr65g"] } } }
{ inputs: { address: { _in: ["addr1q9acqkgp6ah0xl6dt6gxtrmj8ee4ehnzfeq9rcuwrldalfsl94rky7hgymnt04zzmn696ksga7526ycypga0p0q5scfquhr65g"] } } }
]
}
) {
aggregate {
count
}
}
}
query getTransactions {
transactions(
where: {
_or: [
{ outputs: { address: { _in: ["addr1q9acqkgp6ah0xl6dt6gxtrmj8ee4ehnzfeq9rcuwrldalfsl94rky7hgymnt04zzmn696ksga7526ycypga0p0q5scfquhr65g"]} } }
{ inputs: { address: { _in: ["addr1q9acqkgp6ah0xl6dt6gxtrmj8ee4ehnzfeq9rcuwrldalfsl94rky7hgymnt04zzmn696ksga7526ycypga0p0q5scfquhr65g"] } } }
]
}
) {
fee
hash
includedAt
}
}
I've typically found it's better to break up queries like this and join the results in code.
Using an async (Promise.all in NodeJS) task will allow you to run both queries at the same time instead of waiting for one to finish before running the next query.
I've typically found it's better to break up queries like this and join the results in code.
Using an async (Promise.all in NodeJS) task will allow you to run both queries at the same time instead of waiting for one to finish before running the next query.
For transaction aggregation it doesn't work, we can't find a proper address tx count because the same address can be in input and output at the same time. I believe that _or should count the intersection of txs arrays.
It also causes some pagination problems for transaction queries. But maybe you have a solution?
I've faced with the same issue. Individually it takes milliseconds, but together it takes a 30+ seconds
just came into the same issue, you could try something like:
query transactionsCount($address: String!) {
outputs: transactions_aggregate(where: {outputs: {address: {_eq: $address}}}) {
aggregate {
count
}
}
inputs: transactions_aggregate(where: {inputs: {address: {_eq: $address}}}) {
aggregate {
count
}
}
intersect: transactions_aggregate(where: {
_and: {
inputs: {address: {_eq: $address}},
outputs: {address: {_eq: $address}}
}}) {
aggregate {
count
}
}
}
totalTx: outputs + inputs - intersect
< 1s vs 20s+ on a simple 7 transaction count address