Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodlenet
nodejs-services
Commits
e9337330
Commit
e9337330
authored
Oct 14, 2020
by
aleclofabbro
Browse files
limit - test more concurrent queries
parent
f6b13edb
Changes
5
Hide whitespace changes
Inline
Side-by-side
generate_data/populate.js
View file @
e9337330
...
@@ -170,4 +170,44 @@ fragment UserFrag on User {
...
@@ -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
report.20201014.114814.268759.0.001.json
0 → 100644
View file @
e9337330
src/gql-graph/mongo/buildMongoPipeline.ts
View file @
e9337330
...
@@ -56,20 +56,20 @@ export const buildMongoPipeline = (docS: DocumentSelection, notTop?: boolean) =>
...
@@ -56,20 +56,20 @@ export const buildMongoPipeline = (docS: DocumentSelection, notTop?: boolean) =>
}
}
})
})
project
[
field
.
alias
]
=
true
project
[
field
.
alias
]
=
true
mainLookup
.
pipeline
.
push
({
$limit
:
field
.
page
?.
limit
||
10
})
}
else
{
}
else
{
project
[
field
.
alias
]
=
field
.
alias
===
field
.
fieldName
?
true
:
`$
${
field
.
fieldName
}
`
project
[
field
.
alias
]
=
field
.
alias
===
field
.
fieldName
?
true
:
`$
${
field
.
fieldName
}
`
}
}
})
})
// if (notTop) {
const
stages
=
[...
lookups
]
const
stages
=
[...
lookups
,
{
$limit
:
10
}]
if
(
Object
.
keys
(
project
).
length
)
{
if
(
Object
.
keys
(
project
).
length
)
{
stages
.
push
({
$project
:
project
})
stages
.
push
({
$project
:
project
})
}
}
return
stages
if
(
notTop
)
{
// } else {
return
stages
// const stages = lookups[0].$lookup.pipeline
}
else
{
//
return stages
return
[{
$limit
:
1
},
...
stages
]
//
}
}
}
}
function
renameMatchFields
(
match
:
any
):
any
{
function
renameMatchFields
(
match
:
any
):
any
{
...
...
src/http/index.ts
View file @
e9337330
...
@@ -30,14 +30,28 @@ const executor: GraphQLServerOptions['executor'] = async (requestContext) => {
...
@@ -30,14 +30,28 @@ const executor: GraphQLServerOptions['executor'] = async (requestContext) => {
const
pipeline
=
buildMongoPipeline
(
documentSelection
)
const
pipeline
=
buildMongoPipeline
(
documentSelection
)
console
.
log
(
'
executor pipeline
'
,
JSON
.
stringify
(
pipeline
,
null
,
2
))
console
.
log
(
'
executor pipeline
'
,
JSON
.
stringify
(
pipeline
,
null
,
2
))
const
coll
=
await
graphCollection
<
any
>
()
const
coll
=
await
graphCollection
<
any
>
()
// for (let i = 0; i < 100; i++) {
// coll.aggregate(pipeline).toArray()
// }
const
start
=
Number
(
new
Date
())
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
)
console
.
log
(
'
elapsed time
'
,
Number
(
new
Date
())
-
start
)
return
{
data
:
data
[
0
]
}
return
{
data
}
}
}
return
Promise
.
resolve
(
res
)
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)
}
}
src/index.ts
View file @
e9337330
...
@@ -6,10 +6,18 @@ import * as logger from './util/logger'
...
@@ -6,10 +6,18 @@ import * as logger from './util/logger'
graphCollection
().
then
(
async
(
collection
)
=>
{
graphCollection
().
then
(
async
(
collection
)
=>
{
await
collection
.
createIndexes
([
await
collection
.
createIndexes
([
{
key
:
{
__typename
:
1
,
_id
:
1
},
sparse
:
true
,
},
{
{
key
:
{
__typename
:
1
,
username
:
1
},
key
:
{
__typename
:
1
,
username
:
1
},
sparse
:
true
,
sparse
:
true
,
},
},
{
key
:
{
username
:
1
},
sparse
:
true
,
},
{
{
key
:
{
__typename
:
1
,
_obj
:
1
},
key
:
{
__typename
:
1
,
_obj
:
1
},
sparse
:
true
,
sparse
:
true
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment