Add stats to import sample data

This commit is contained in:
Laurent Nguyen 2022-05-04 12:20:46 +02:00
Родитель 2bd880f22c
Коммит 5513997c65
2 изменённых файлов: 20 добавлений и 4 удалений

Просмотреть файл

@ -289,7 +289,11 @@ export class AppContext {
* @param sampleData
* @returns Promise with inserted count
*/
public async insertDocuments(server: string, sampleData: SampleData, databaseName?: string): Promise<number> {
public async insertDocuments(
server: string,
sampleData: SampleData,
databaseName?: string
): Promise<{ count: number; elapsedTimeMS: number }> {
return new Promise(async (resolve, reject) => {
// should already be connected
const client = this._mongoClients.get(server);
@ -307,6 +311,7 @@ export class AppContext {
}
showStatusBarItem(localize("insertingData", "Inserting documents ({0})...", sampleData.data.length));
const startMS = new Date().getTime();
const result = await collection.bulkWrite(
sampleData.data.map((doc) => ({
insertOne: {
@ -314,13 +319,18 @@ export class AppContext {
},
}))
);
const endMS = new Date().getTime();
hideStatusBarItem();
if (result.insertedCount === undefined || result.insertedCount < sampleData.data.length) {
reject(localize("failInsertDocs", "Failed to insert all documents {0}", sampleData.data.length));
return;
}
return resolve(result.insertedCount);
return resolve({
count: result.insertedCount,
elapsedTimeMS: endMS - startMS,
});
});
}
}

Просмотреть файл

@ -66,8 +66,14 @@ export const ingestSampleMongoData = async (
progress.report({
message: localize("importingSampleData", "Importing sample data..."),
});
const count = await appContext.insertDocuments(serverName, sampleData, databaseName);
vscode.window.showInformationMessage(localize("successInsertDoc", "Successfully inserted {0} docs", count));
const { count, elapsedTimeMS } = await appContext.insertDocuments(serverName, sampleData, databaseName);
vscode.window.showInformationMessage(
localize(
"successInsertDoc",
`Successfully inserted {0} documents (took ${Math.floor(elapsedTimeMS / 1000)}s)`,
count
)
);
}
);
} catch (e) {