Reduce DB creation time to 5,0 seconds
This commit is contained in:
@@ -200,13 +200,16 @@ export async function prepopulateDatabase() {
|
|||||||
|
|
||||||
////////// Account Tables //////////
|
////////// Account Tables //////////
|
||||||
|
|
||||||
|
let addresses = []
|
||||||
|
let payments = []
|
||||||
|
|
||||||
AccountRole.bulkCreate(accountRoles.data)
|
AccountRole.bulkCreate(accountRoles.data)
|
||||||
|
|
||||||
for (let account of accounts.data) {
|
for (let account of accounts.data) {
|
||||||
await Account.create(account)
|
await Account.create(account)
|
||||||
.then(async dataset => {
|
.then(async dataset => {
|
||||||
for (let address of account.addresses) {
|
for (let address of account.addresses) {
|
||||||
await Address.create({
|
addresses.push({
|
||||||
accountId: dataset.dataValues.id,
|
accountId: dataset.dataValues.id,
|
||||||
street: address.street,
|
street: address.street,
|
||||||
houseNumber: address.houseNumber,
|
houseNumber: address.houseNumber,
|
||||||
@@ -216,19 +219,27 @@ export async function prepopulateDatabase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let payment of account.payments) {
|
for (let payment of account.payments) {
|
||||||
await Payment.create({
|
payments.push({
|
||||||
accountId: dataset.dataValues.id,
|
accountId: dataset.dataValues.id,
|
||||||
bankName: payment.bankName,
|
bankName: payment.bankName,
|
||||||
iban: payment.iban
|
iban: payment.iban
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Address.bulkCreate(addresses)
|
||||||
|
Payment.bulkCreate(payments)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////// Band and Concert Tables //////////
|
////////// Band and Concert Tables //////////
|
||||||
|
|
||||||
|
let bandGenres = []
|
||||||
|
let bandMembers = []
|
||||||
|
let concerts = []
|
||||||
|
let ratings = []
|
||||||
|
|
||||||
for(let band of bandsConcerts.bands) {
|
for(let band of bandsConcerts.bands) {
|
||||||
band.imageMembers = "http://localhost:3000/static/" + band.imageMembers
|
band.imageMembers = "http://localhost:3000/static/" + band.imageMembers
|
||||||
band.images = band.images.map(image => "http://localhost:3000/static/" + image)
|
band.images = band.images.map(image => "http://localhost:3000/static/" + image)
|
||||||
@@ -248,7 +259,7 @@ export async function prepopulateDatabase() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(async genreDataset => {
|
.then(async genreDataset => {
|
||||||
await BandGenre.create({
|
bandGenres.push({
|
||||||
genreId: genreDataset[0].dataValues.id,
|
genreId: genreDataset[0].dataValues.id,
|
||||||
bandId: dataset.dataValues.id
|
bandId: dataset.dataValues.id
|
||||||
})
|
})
|
||||||
@@ -262,7 +273,7 @@ export async function prepopulateDatabase() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(async account => {
|
.then(async account => {
|
||||||
await Rating.create({
|
ratings.push({
|
||||||
accountId: account.dataValues.id,
|
accountId: account.dataValues.id,
|
||||||
rating: rating.rating,
|
rating: rating.rating,
|
||||||
bandId: dataset.dataValues.id
|
bandId: dataset.dataValues.id
|
||||||
@@ -273,7 +284,7 @@ export async function prepopulateDatabase() {
|
|||||||
for (let member of band.members) {
|
for (let member of band.members) {
|
||||||
member.image = "http://localhost:3000/static/" + member.image
|
member.image = "http://localhost:3000/static/" + member.image
|
||||||
|
|
||||||
await Member.create({
|
bandMembers.push({
|
||||||
name: member.name,
|
name: member.name,
|
||||||
image: member.image,
|
image: member.image,
|
||||||
bandId: dataset.dataValues.id
|
bandId: dataset.dataValues.id
|
||||||
@@ -288,7 +299,7 @@ export async function prepopulateDatabase() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(async location => {
|
.then(async location => {
|
||||||
await Concert.create({
|
concerts.push({
|
||||||
date: concert.date,
|
date: concert.date,
|
||||||
name: concertGroup.name,
|
name: concertGroup.name,
|
||||||
price: concert.price,
|
price: concert.price,
|
||||||
@@ -304,10 +315,17 @@ export async function prepopulateDatabase() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BandGenre.bulkCreate(bandGenres)
|
||||||
|
Member.bulkCreate(bandMembers)
|
||||||
|
Concert.bulkCreate(concerts)
|
||||||
|
Rating.bulkCreate(ratings)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////// Order and Ticket Tables //////////
|
////////// Order and Ticket Tables //////////
|
||||||
|
|
||||||
|
let tickets = []
|
||||||
|
|
||||||
for (let order of orders.orders) {
|
for (let order of orders.orders) {
|
||||||
let account = await Account.findOne({
|
let account = await Account.findOne({
|
||||||
where: {
|
where: {
|
||||||
@@ -363,7 +381,7 @@ export async function prepopulateDatabase() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(async seat => {
|
.then(async seat => {
|
||||||
await Ticket.create({
|
tickets.push({
|
||||||
orderId: dataset.dataValues.id,
|
orderId: dataset.dataValues.id,
|
||||||
concertId: concert.dataValues.id,
|
concertId: concert.dataValues.id,
|
||||||
orderPrice: ticket.orderPrice,
|
orderPrice: ticket.orderPrice,
|
||||||
@@ -374,6 +392,8 @@ export async function prepopulateDatabase() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Ticket.bulkCreate(tickets)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(moment().diff(start))
|
console.log(moment().diff(start))
|
||||||
|
|||||||
Reference in New Issue
Block a user