mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
refactor(backend): reduce seed time (#8662)
* reduce seed time - only 1000 additional users - chat only for 100 additional users - logs to see where its at * lint
This commit is contained in:
parent
0365cee45e
commit
e6d3e5132e
@ -31,23 +31,26 @@ CONFIG.SEND_MAIL = true
|
|||||||
const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
||||||
|
|
||||||
;(async function () {
|
;(async function () {
|
||||||
|
/* eslint-disable-next-line no-console */
|
||||||
|
console.log('Seeded Data...')
|
||||||
|
|
||||||
let authenticatedUser = null
|
let authenticatedUser = null
|
||||||
const driver = getDriver()
|
const driver = getDriver()
|
||||||
const neode = getNeode()
|
const neode = getNeode()
|
||||||
|
const { server } = createServer({
|
||||||
|
context: () => {
|
||||||
|
return {
|
||||||
|
driver,
|
||||||
|
neode,
|
||||||
|
user: authenticatedUser,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const { mutate } = createTestClient(server)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { server } = createServer({
|
// eslint-disable-next-line no-console
|
||||||
context: () => {
|
console.log('seed', 'locations')
|
||||||
return {
|
|
||||||
driver,
|
|
||||||
neode,
|
|
||||||
user: authenticatedUser,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
const { mutate } = createTestClient(server)
|
|
||||||
|
|
||||||
// locations
|
|
||||||
const Hamburg = await Factory.build('location', {
|
const Hamburg = await Factory.build('location', {
|
||||||
id: 'region.5127278006398860',
|
id: 'region.5127278006398860',
|
||||||
name: 'Hamburg',
|
name: 'Hamburg',
|
||||||
@ -150,7 +153,9 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
} = await trophies()
|
} = await trophies()
|
||||||
|
|
||||||
const { verificationAdmin, verificationModerator, verificationDeveloper } = await verification()
|
const { verificationAdmin, verificationModerator, verificationDeveloper } = await verification()
|
||||||
// users
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'users')
|
||||||
const peterLustig = await Factory.build(
|
const peterLustig = await Factory.build(
|
||||||
'user',
|
'user',
|
||||||
{
|
{
|
||||||
@ -243,7 +248,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
await jennyRostock.relateTo(Paris, 'isIn')
|
await jennyRostock.relateTo(Paris, 'isIn')
|
||||||
await huey.relateTo(Paris, 'isIn')
|
await huey.relateTo(Paris, 'isIn')
|
||||||
|
|
||||||
// badges
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'badges')
|
||||||
await peterLustig.relateTo(trophyRacoon, 'rewarded')
|
await peterLustig.relateTo(trophyRacoon, 'rewarded')
|
||||||
await peterLustig.relateTo(trophyRhino, 'rewarded')
|
await peterLustig.relateTo(trophyRhino, 'rewarded')
|
||||||
await peterLustig.relateTo(trophyWolf, 'rewarded')
|
await peterLustig.relateTo(trophyWolf, 'rewarded')
|
||||||
@ -286,7 +292,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
await louie.relateTo(trophyRabbit, 'rewarded')
|
await louie.relateTo(trophyRabbit, 'rewarded')
|
||||||
await louie.relateTo(trophyRabbit, 'selected', { slot: 4 })
|
await louie.relateTo(trophyRabbit, 'selected', { slot: 4 })
|
||||||
|
|
||||||
// Friends
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'friends')
|
||||||
await peterLustig.relateTo(bobDerBaumeister, 'friends')
|
await peterLustig.relateTo(bobDerBaumeister, 'friends')
|
||||||
await peterLustig.relateTo(jennyRostock, 'friends')
|
await peterLustig.relateTo(jennyRostock, 'friends')
|
||||||
await bobDerBaumeister.relateTo(jennyRostock, 'friends')
|
await bobDerBaumeister.relateTo(jennyRostock, 'friends')
|
||||||
@ -307,7 +314,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
await dagobert.relateTo(dewey, 'blocked')
|
await dagobert.relateTo(dewey, 'blocked')
|
||||||
await dagobert.relateTo(louie, 'blocked')
|
await dagobert.relateTo(louie, 'blocked')
|
||||||
|
|
||||||
// categories
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'categories')
|
||||||
for (const category of categories) {
|
for (const category of categories) {
|
||||||
await Factory.build('category', {
|
await Factory.build('category', {
|
||||||
id: category.id,
|
id: category.id,
|
||||||
@ -317,7 +325,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// tags
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'tags')
|
||||||
const environment = await Factory.build('tag', {
|
const environment = await Factory.build('tag', {
|
||||||
id: 'Environment',
|
id: 'Environment',
|
||||||
})
|
})
|
||||||
@ -331,7 +340,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
id: 'Freedom',
|
id: 'Freedom',
|
||||||
})
|
})
|
||||||
|
|
||||||
// groups
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'groups')
|
||||||
authenticatedUser = await peterLustig.toJson()
|
authenticatedUser = await peterLustig.toJson()
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: createGroupMutation(),
|
mutation: createGroupMutation(),
|
||||||
@ -386,7 +396,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// post into group
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'group posts')
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: createPostMutation(),
|
mutation: createPostMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
@ -484,7 +495,6 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
roleInGroup: 'owner',
|
roleInGroup: 'owner',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
// post into group
|
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: createPostMutation(),
|
mutation: createPostMutation(),
|
||||||
variables: {
|
variables: {
|
||||||
@ -601,7 +611,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create Events (by peter lustig)
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'events')
|
||||||
authenticatedUser = await peterLustig.toJson()
|
authenticatedUser = await peterLustig.toJson()
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|
||||||
@ -659,7 +670,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
eventStart: new Date(now.getFullYear(), now.getMonth(), now.getDate() - 3).toISOString(),
|
eventStart: new Date(now.getFullYear(), now.getMonth(), now.getDate() - 3).toISOString(),
|
||||||
})
|
})
|
||||||
|
|
||||||
// posts (articles)
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'posts')
|
||||||
const p0 = await Factory.build(
|
const p0 = await Factory.build(
|
||||||
'post',
|
'post',
|
||||||
{
|
{
|
||||||
@ -816,7 +828,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
// invite code
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'invitecodes')
|
||||||
await Factory.build(
|
await Factory.build(
|
||||||
'inviteCode',
|
'inviteCode',
|
||||||
{
|
{
|
||||||
@ -881,6 +894,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
|
|
||||||
authenticatedUser = null
|
authenticatedUser = null
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'comments')
|
||||||
authenticatedUser = await dewey.toJson()
|
authenticatedUser = await dewey.toJson()
|
||||||
const mentionInComment1 =
|
const mentionInComment1 =
|
||||||
'I heard <a class="mention" data-mention-id="u3" href="/profile/u3">@jenny-rostock</a> has practiced it for 3 years now.'
|
'I heard <a class="mention" data-mention-id="u3" href="/profile/u3">@jenny-rostock</a> has practiced it for 3 years now.'
|
||||||
@ -1087,6 +1102,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
await huey.relateTo(p9, 'shouted')
|
await huey.relateTo(p9, 'shouted')
|
||||||
await louie.relateTo(p10, 'shouted')
|
await louie.relateTo(p10, 'shouted')
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'reports')
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const reports: any[] = []
|
const reports: any[] = []
|
||||||
reports.push(
|
reports.push(
|
||||||
@ -1195,9 +1212,11 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
closed: true,
|
closed: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'users additional')
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const additionalUsers: any[] = []
|
const additionalUsers: any[] = []
|
||||||
for (let i = 0; i < 3000; i++) {
|
for (let i = 0; i < 1000; i++) {
|
||||||
const user = await Factory.build('user')
|
const user = await Factory.build('user')
|
||||||
await jennyRostock.relateTo(user, 'following')
|
await jennyRostock.relateTo(user, 'following')
|
||||||
await user.relateTo(jennyRostock, 'following')
|
await user.relateTo(jennyRostock, 'following')
|
||||||
@ -1510,7 +1529,8 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
|
|
||||||
await Factory.build('donations')
|
await Factory.build('donations')
|
||||||
|
|
||||||
// Chat
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('seed', 'chat')
|
||||||
authenticatedUser = await huey.toJson()
|
authenticatedUser = await huey.toJson()
|
||||||
const { data: roomHueyPeter } = await mutate({
|
const { data: roomHueyPeter } = await mutate({
|
||||||
mutation: createRoomMutation(),
|
mutation: createRoomMutation(),
|
||||||
@ -1564,7 +1584,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const user of additionalUsers) {
|
for (const user of additionalUsers.slice(0, 99)) {
|
||||||
authenticatedUser = await jennyRostock.toJson()
|
authenticatedUser = await jennyRostock.toJson()
|
||||||
const { data: room } = await mutate({
|
const { data: room } = await mutate({
|
||||||
mutation: createRoomMutation(),
|
mutation: createRoomMutation(),
|
||||||
@ -1592,16 +1612,15 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable-next-line no-console */
|
|
||||||
console.log('Seeded Data...')
|
|
||||||
await driver.close()
|
|
||||||
neode.close()
|
|
||||||
process.exit(0)
|
|
||||||
// eslint-disable-next-line no-catch-all/no-catch-all
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
/* eslint-disable-next-line no-console */
|
/* eslint-disable-next-line no-console */
|
||||||
console.error(err)
|
console.error(err)
|
||||||
process.exit(1)
|
throw err
|
||||||
|
} finally {
|
||||||
|
await server.stop()
|
||||||
|
await driver.close()
|
||||||
|
// eslint-disable-next-line @typescript-eslint/await-thenable
|
||||||
|
await neode.close()
|
||||||
|
process.exit(0)
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user