Commit e9337330 authored by aleclofabbro's avatar aleclofabbro
Browse files

limit - test more concurrent queries

parent f6b13edb
......@@ -170,4 +170,44 @@ fragment UserFrag on User {
# }
# }
*/
/**
{
graph(query: {User: {username: {_gt: "0"}}}, page: {limit: 10}) {
... on User {
...UserFrag
}
}
}
fragment UserFrag on User {
username
Knows: _rel(page: {limit: 10}) {
... on Knows {
user: _obj {
... on User {
username
FollowsAndKnows: _rel(page: {limit:40}) {
... on Follows {
user: _obj {
... on User {
username
}
}
}
... on Knows {
user: _obj {
... on User {
username
}
}
}
}
}
}
}
}
}
*/
\ No newline at end of file
......@@ -56,20 +56,20 @@ export const buildMongoPipeline = (docS: DocumentSelection, notTop?: boolean) =>
}
})
project[field.alias] = true
mainLookup.pipeline.push({ $limit: field.page?.limit || 10 })
} else {
project[field.alias] = field.alias === field.fieldName ? true : `$${field.fieldName}`
}
})
// if (notTop) {
const stages = [...lookups, { $limit: 10 }]
const stages = [...lookups]
if (Object.keys(project).length) {
stages.push({ $project: project })
}
return stages
// } else {
// const stages = lookups[0].$lookup.pipeline
// return stages
// }
if (notTop) {
return stages
} else {
return [{ $limit: 1 }, ...stages]
}
}
function renameMatchFields(match: any): any {
......
......@@ -30,14 +30,28 @@ const executor: GraphQLServerOptions['executor'] = async (requestContext) => {
const pipeline = buildMongoPipeline(documentSelection)
console.log('executor pipeline', JSON.stringify(pipeline, null, 2))
const coll = await graphCollection<any>()
// for (let i = 0; i < 100; i++) {
// coll.aggregate(pipeline).toArray()
// }
const start = Number(new Date())
const data = await coll.aggregate(pipeline).toArray()
moreQueries(20, pipeline)
const data = await coll.aggregate(JSON.parse(JSON.stringify(pipeline))).next()
console.log(Number(new Date()) - start)
return { data: data[0] }
console.log('elapsed time', Number(new Date()) - start)
return { data }
}
return Promise.resolve(res)
}
function moreQueries(amount: number, pipeline: any[]) {
for (let i = 0; i < amount; i++) {
graphCollection().then(async (coll) => {
const curs = coll.aggregate([...pipeline, { $unwind: '$graph' }])
// .group({ _id: null, count: { $sum: 1 } })
// console.log((
await curs.toArray()
// ).length)
curs.close()
})
// .then(console.log)
}
}
......@@ -6,10 +6,18 @@ import * as logger from './util/logger'
graphCollection().then(async (collection) => {
await collection.createIndexes([
{
key: { __typename: 1, _id: 1 },
sparse: true,
},
{
key: { __typename: 1, username: 1 },
sparse: true,
},
{
key: { username: 1 },
sparse: true,
},
{
key: { __typename: 1, _obj: 1 },
sparse: true,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment