Hello,
Following the guide here Migrating to Prismic - Documentation - Prismic, I've been able to quickly create a script to import 40 document in Prismic.
Unfortunately it has been shown to be really slow.
The document custom type is a Tag with one field, a name.
This import took 7 minutes which, I think should have take way less.
So far I'm happy with my experience with Prismic but a bit worried about this performance issue.
The code is very simple and follow your documentation :
import 'dotenv/config'
import * as prismic from '@prismicio/client'
import slugify from '@sindresorhus/slugify'
import newstags from './news-tag.json' assert { type: 'json' }
const repositoryName = process.env.PRISMIC_REPO_NAME
const writeClient = prismic.createWriteClient(repositoryName, {
writeToken: process.env.PRISMIC_WRITE_TOKEN
})
const createDocument = (tag) => {
migration.createDocument(
{
uid: slugify(tag),
type: 'news_tags',
lang: 'fr-fr',
tags: [tag],
data: {
name: tag
}
},
tag
)
}
const migration = prismic.createMigration()
for (const tag of newstags) {
createDocument(tag)
}
await writeClient.migrate(migration, {
reporter: (event) => console.log(event)
})
Hey team; Could you let us know when you first noticed this issue? Timestamps would be really helpful. So far, we haven’t received other reports or seen any errors logged.
Thank you for providing detailed information about the issue you’re experiencing with the Migration API’s performance.
Given that you’re observing delays only when using the JavaScript library and not with manual API calls, there might be an issue within the script or how the library handles requests. To help identify the bottleneck, consider adding logging to measure the time taken for each request and response within your script. This can provide insights into where the delays are occurring.
Updated Script with Logging
import 'dotenv/config'
import * as prismic from '@prismicio/client'
import slugify from '@sindresorhus/slugify'
import newstags from './news-tag.json' assert { type: 'json' }
const repositoryName = process.env.PRISMIC_REPO_NAME
const writeClient = prismic.createWriteClient(repositoryName, {
writeToken: process.env.PRISMIC_WRITE_TOKEN
})
// Create a migration instance
const migration = prismic.createMigration()
const createDocument = (tag) => {
const startTime = Date.now(); // Start timing
migration.createDocument(
{
uid: slugify(tag),
type: 'news_tags',
lang: 'fr-fr',
tags: [tag],
data: {
name: tag
}
},
tag
)
const endTime = Date.now(); // End timing
console.log(`[DEBUG] Created migration entry for tag: "${tag}" in ${endTime - startTime}ms`)
}
console.log(`[INFO] Starting migration for ${newstags.length} tags...`)
for (const tag of newstags) {
createDocument(tag)
}
const migrationStartTime = Date.now(); // Start timing full migration
await writeClient.migrate(migration, {
reporter: (event) => {
const timestamp = new Date().toISOString();
console.log(`[REPORTER] ${timestamp} - ${JSON.stringify(event)}`);
}
})
const migrationEndTime = Date.now(); // End timing full migration
console.log(`[SUMMARY] Migration completed in ${migrationEndTime - migrationStartTime}ms`);
What This Logs:
1. Time taken for each createDocument call – helps see if document creation itself is slow.
2. Total migration time – tracks how long the writeClient.migrate() function takes.
3. Detailed migration events – logs migration progress through reporter.
Next Steps for Debugging:
• Run the script and check which part is slow (document creation or the migration execution).
• If createDocument is fast but migrate() is slow, the bottleneck is likely on Prismic’s API side.
• If logs show inconsistent delays, network latency might be affecting performance.
• If some migrations fail or timeout, check for rate limiting or API response errors.
Once we have more information, we’ll be better positioned to diagnose the issue and recommend a solution.