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
64fbeaae
Commit
64fbeaae
authored
Oct 14, 2020
by
aleclofabbro
Browse files
better populate usernames, populate indexes
parent
e9337330
Changes
3
Hide whitespace changes
Inline
Side-by-side
generate_data/populate.js
View file @
64fbeaae
...
...
@@ -13,12 +13,49 @@ const batchSize = Number(process.argv[4]) || 500
try
{
await
collection
.
drop
()
}
catch
{
}
console
.
log
(
`making nodes`
)
await
nodes
(
collection
,
nNodes
,
batchSize
)
console
.
log
(
`nodes done,
${
nodeIds
.
length
}
`
)
console
.
log
(
`making edges`
)
await
edges
(
collection
,
nEdges
,
batchSize
)
console
.
log
(
`edges done`
)
console
.
log
(
`creating indexes`
)
await
await
collection
.
createIndexes
([
{
key
:
{
__typename
:
1
,
_id
:
1
},
sparse
:
true
,
unique
:
true
,
},
{
key
:
{
__typename
:
1
,
username
:
1
},
partialFilterExpression
:
{
__typename
:
{
$eq
:
'
User
'
}
},
//sparse: true,
},
{
key
:
{
username
:
1
},
// partialFilterExpression: { __typename: { $eq: 'User' } },
sparse
:
true
,
},
{
key
:
{
__typename
:
1
,
_obj
:
1
},
// partialFilterExpression: { $and: [{ _obj: { $exists: true } }] },
sparse
:
true
,
},
{
key
:
{
__typename
:
1
,
_subj
:
1
},
// partialFilterExpression: { $and: [{ _subj: { $exists: true } }] },
sparse
:
true
,
},
{
key
:
{
__typename
:
1
,
_subj
:
1
,
_obj
:
1
},
sparse
:
true
,
// partialFilterExpression: { $and: [{ _subj: { $exists: true } }, { _obj: { $exists: true } }] },
// unique: true,
},
])
console
.
log
(
`indexes done`
)
//try { await tempCollection.drop() } catch { }
client
.
close
()
})()
...
...
@@ -32,7 +69,7 @@ async function nodes(collection, n_nodes, batch_size) {
while
(
users
.
length
<
batch_size
)
{
users
.
push
({
__typename
:
'
User
'
,
username
:
faker
.
internet
.
userName
(),
username
:
faker
.
internet
.
userName
()
+
'
_
'
+
Math
.
random
().
toString
(
36
).
substring
(
2
)
,
})
}
const
res
=
await
collection
.
insertMany
(
users
)
...
...
src/http/index.ts
View file @
64fbeaae
...
...
@@ -30,8 +30,8 @@ const executor: GraphQLServerOptions['executor'] = async (requestContext) => {
const
pipeline
=
buildMongoPipeline
(
documentSelection
)
console
.
log
(
'
executor pipeline
'
,
JSON
.
stringify
(
pipeline
,
null
,
2
))
const
coll
=
await
graphCollection
<
any
>
()
moreQueries
(
100
,
pipeline
)
const
start
=
Number
(
new
Date
())
moreQueries
(
20
,
pipeline
)
const
data
=
await
coll
.
aggregate
(
JSON
.
parse
(
JSON
.
stringify
(
pipeline
))).
next
()
console
.
log
(
'
elapsed time
'
,
Number
(
new
Date
())
-
start
)
...
...
src/index.ts
View file @
64fbeaae
import
{
httpPort
}
from
'
./env
'
import
{
schema
}
from
'
./gql
'
import
{
start
}
from
'
./http
'
import
{
graphCollection
}
from
'
./mongo/collection
'
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
,
},
{
key
:
{
__typename
:
1
,
_subj
:
1
},
sparse
:
true
,
},
])
start
({
httpPort
,
schema
,
}).
addListener
(
'
listening
'
,
()
=>
{
logger
.
simpleLogger
.
info
(
`server started on port
${
httpPort
}
`
)
})
start
({
httpPort
,
schema
,
}).
addListener
(
'
listening
'
,
()
=>
{
logger
.
simpleLogger
.
info
(
`server started on port
${
httpPort
}
`
)
})
Write
Preview
Markdown
is supported
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