我有一个附加到 PostgreSQL 数据库的 Prisma (1.14.2) 服务正在运行。我需要通过 Prisma 连接器插入许多与 PostgreSQL 数据库具有一对多关系的节点。现在我正在通过以下方式执行此操作。和strokes
数组samples
包含很多节点:
for (let strokeIndex = 0; strokeIndex < painting.strokes.length; strokeIndex++) {
const stroke = painting.strokes[strokeIndex];
const samples = stroke.samples;
const createdStroke = await PrismaServer.mutation.createStroke({
data: {
myId: stroke.id,
myCreatedAt: new Date(stroke.createdAt),
brushType: stroke.brushType,
color: stroke.color,
randomSeed: stroke.randomSeed,
painting: {connect: {myId: jsonPainting.id}},
samples: { create: samples }
}
});
}
在 128 个笔划和每个笔划 128 个样本(即总共 16348 个样本)的情况下,这大约需要 38 秒。
我想知道是否有办法加快这个过程?特别是因为笔画和样本的数量可以变得更高。我可以使用prisma import ...
,它显示了 6 倍的加速。但我想避免所需的转换为标准化数据格式 (NDF)。
我读到了关于在 PostgreSQL中加速 INSERT 的文章,但我不确定是否以及如何将其应用于 Prisma 连接器。