Skip to content

Commit 4086459

Browse files
authored
feat(compass-collection): Mock Data Generator Script Output Screen QA Items - CLOUDP-356792 (#7567)
* WIP * WIP * Comments
1 parent 762fb43 commit 4086459

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

packages/compass-collection/src/components/mock-data-generator-modal/script-generation-utils.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,49 @@ use(${JSON.stringify(options.databaseName)});
7373
7474
// Document generation function
7575
function generateDocument() {
76-
return ${documentCode};
76+
return ${documentCode};
7777
}
7878
79-
// Generate and insert documents
80-
const documents = [];
81-
for (let i = 0; i < ${options.documentCount}; i++) {
82-
documents.push(generateDocument());
79+
const BATCH_SIZE = 1000; // Number of documents to insert per batch
80+
const TOTAL_DOCUMENTS = ${options.documentCount};
81+
const numBatches = Math.ceil(TOTAL_DOCUMENTS / BATCH_SIZE);
82+
83+
console.log(\`Starting mock data generation for ${options.databaseName.replace(
84+
/[\\`$]/g,
85+
'\\$&'
86+
)}.${options.collectionName.replace(/[\\`$]/g, '\\$&')}\`);
87+
console.log(\`Total documents to generate: \${TOTAL_DOCUMENTS} documents\`);
88+
console.log(\`Batch size: \${BATCH_SIZE} documents per batch\`);
89+
90+
const startTime = new Date();
91+
92+
for (let batchStart = 0; batchStart < TOTAL_DOCUMENTS; batchStart += BATCH_SIZE) {
93+
const batchEnd = Math.min(batchStart + BATCH_SIZE, TOTAL_DOCUMENTS);
94+
const batchSize = batchEnd - batchStart;
95+
96+
console.log(\`Generating batch \${Math.floor(batchStart / BATCH_SIZE) + 1} of \${numBatches} (\${batchSize} documents)...\`);
97+
98+
// Generate documents for this batch
99+
const batchDocuments = [];
100+
for (let i = 0; i < batchSize; i++) {
101+
batchDocuments.push(generateDocument());
102+
}
103+
104+
// Insert the batch
105+
db.getCollection(${JSON.stringify(
106+
options.collectionName
107+
)}).insertMany(batchDocuments);
108+
109+
console.log(\`Batch inserted successfully.\`);
83110
}
84111
85-
// Insert documents into collection
86-
db.getCollection(${JSON.stringify(
87-
options.collectionName
88-
)}).insertMany(documents);
112+
const endTime = new Date();
113+
const duration = ((endTime - startTime) / 1000).toFixed(2);
89114
90-
console.log(\`Successfully inserted \${documents.length} documents into ${options.databaseName.replace(
91-
/[\\`$]/g, // Escape backslashes, backticks and dollar signs
115+
console.log(\`\\n=== Mock Data Generation Complete ===\`);
116+
console.log(\`Total time: \${duration} seconds\`);
117+
console.log(\`Collection: ${options.databaseName.replace(
118+
/[\\`$]/g,
92119
'\\$&'
93120
)}.${options.collectionName.replace(/[\\`$]/g, '\\$&')}\`);`;
94121

packages/compass-collection/src/components/mock-data-generator-modal/script-screen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const ScriptScreen = ({
180180
onScriptCopy({ step: DataGenerationStep.INSTALL_FAKERJS })
181181
}
182182
>
183-
npm install @faker-js/faker
183+
npm install @faker-js/faker@9
184184
</Copyable>
185185
</li>
186186
</ul>
@@ -190,8 +190,8 @@ const ScriptScreen = ({
190190
1. Create a .js file with the following script
191191
</Body>
192192
<Body className={sectionInstructionStyles}>
193-
In the directory that you created, create a file named
194-
mockdatascript.js (or any name you&apos;d like).
193+
In the directory that you created, create a file named{' '}
194+
<strong>mockdatascript.js</strong> (or any name you&apos;d like).
195195
</Body>
196196
<Code
197197
copyButtonAppearance={scriptResult.success ? 'hover' : 'persist'}

0 commit comments

Comments
 (0)