From 4592786da3720380dde307d89ae2828d4638029f Mon Sep 17 00:00:00 2001 From: tyaginidhi Date: Fri, 30 Sep 2022 12:36:44 +0530 Subject: [PATCH] First time load for file fix and other optimizations (#302) * FIrst time load for file fix and other optimizations * Update fileSystemProvider.ts --- src/web/client/common/fileSystemProvider.ts | 41 ++++++++------------ src/web/client/common/remoteFetchProvider.ts | 11 +++--- src/web/client/extension.ts | 4 ++ 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/web/client/common/fileSystemProvider.ts b/src/web/client/common/fileSystemProvider.ts index 820ea8f1..db211fb6 100644 --- a/src/web/client/common/fileSystemProvider.ts +++ b/src/web/client/common/fileSystemProvider.ts @@ -78,7 +78,7 @@ export class PortalsFS implements vscode.FileSystemProvider { if (castedError.code === vscode.FileSystemError.FileNotFound.name) { const powerPlatformContext = await PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext(); - if (powerPlatformContext.rootDirectory && uri.toString().includes(powerPlatformContext.rootDirectory.toString())) { + if (powerPlatformContext.rootDirectory && uri.toString().toLowerCase() === powerPlatformContext.rootDirectory.toString().toLowerCase()) { await this._loadFromDataverseToVFS(); } } @@ -96,10 +96,17 @@ export class PortalsFS implements vscode.FileSystemProvider { const castedError = error as vscode.FileSystemError; if (castedError.code === vscode.FileSystemError.FileNotFound.name) { - await this._loadFileFromDataverseToVFS(uri); - - const data = await this._lookupAsFile(uri, false); - return data.data; + const rootDirectory = PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext().rootDirectory; + + if (rootDirectory + && uri.toString().includes(rootDirectory.toString())) { + if (PathHasEntityFolderName(uri.toString())) { + await this._loadFromDataverseToVFS(); + + const data = await this._lookupAsFile(uri, false); + return data.data; + } + } } } return new Uint8Array(); @@ -122,14 +129,15 @@ export class PortalsFS implements vscode.FileSystemProvider { entry = new File(basename); parent.entries.set(basename, entry); this._fireSoon({ type: vscode.FileChangeType.Created, uri }); + } else if (PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext().saveDataMap.has(uri.fsPath)) { + // Save data to dataverse + await this._saveFileToDataverseFromVFS(uri, content); } + entry.mtime = Date.now(); entry.size = content.byteLength; entry.data = content; - // Save data to dataverse - await this._saveFileToDataverseFromVFS(uri, content); - this._fireSoon({ type: vscode.FileChangeType.Changed, uri }); } @@ -230,23 +238,6 @@ export class PortalsFS implements vscode.FileSystemProvider { } // --- Dataverse calls - private async _loadFileFromDataverseToVFS(uri: vscode.Uri) { - const rootDirectory = PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext().rootDirectory; - - if (rootDirectory - && uri.toString().includes(rootDirectory.toString())) { - if (PathHasEntityFolderName(uri.toString())) { - - await this._loadFromDataverseToVFS(); - - if (PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext().defaultFileUri !== uri) { - throw vscode.FileSystemError.FileNotFound(); - } - } else { - this.readDirectory(rootDirectory); - } - } - } private async _loadFromDataverseToVFS() { const powerPlatformContext = await PowerPlatformExtensionContextManager.authenticateAndUpdateDataverseProperties(); diff --git a/src/web/client/common/remoteFetchProvider.ts b/src/web/client/common/remoteFetchProvider.ts index 30a62f6c..6d678fa4 100644 --- a/src/web/client/common/remoteFetchProvider.ts +++ b/src/web/client/common/remoteFetchProvider.ts @@ -65,7 +65,7 @@ export async function fetchDataFromDataverseAndUpdateVFS( } for (let counter = 0; counter < data.length; counter++) { - createContentFiles(data[counter], entity, queryParamsMap, entitiesSchemaMap, languageIdCodeMap, portalFs, entityId, websiteIdToLanguage); + await createContentFiles(data[counter], entity, queryParamsMap, entitiesSchemaMap, languageIdCodeMap, portalFs, entityId, websiteIdToLanguage); } } catch (error) { const authError = (error as Error)?.message; @@ -155,9 +155,9 @@ async function createContentFiles( result[Constants.MIMETYPE]); } - PowerPlatformExtensionContextManager.updateSingleFileUrisInContext(vscode.Uri.parse(fileUri)); + await PowerPlatformExtensionContextManager.updateSingleFileUrisInContext(vscode.Uri.parse(fileUri)); - // Display only the last file + // Not awaited intentionally vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(fileUri), {background: true, preview: false}); } } @@ -174,9 +174,8 @@ async function createVirtualFile( ) { const saveEntityDetails = new SaveEntityDetails(entityId, entity, saveDataAttribute, useBase64Encoding, mimeType); const dataMap: Map = PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext().saveDataMap; - - await portalsFS.writeFile(vscode.Uri.parse(fileUri), new TextEncoder().encode(data), { create: true, overwrite: true }); dataMap.set(vscode.Uri.parse(fileUri).fsPath, saveEntityDetails); + await PowerPlatformExtensionContextManager.updateSaveDataDetailsInContext(dataMap); - PowerPlatformExtensionContextManager.updateSaveDataDetailsInContext(dataMap); + await portalsFS.writeFile(vscode.Uri.parse(fileUri), new TextEncoder().encode(data), { create: true, overwrite: true }); } diff --git a/src/web/client/extension.ts b/src/web/client/extension.ts index b4226975..fd4d67fc 100644 --- a/src/web/client/extension.ts +++ b/src/web/client/extension.ts @@ -62,11 +62,15 @@ export function activate(context: vscode.ExtensionContext): void { switch (appName) { case 'portal': { sendExtensionInitQueryParametersTelemetry(searchParams); + const isFirstRun = context.globalState.get(IS_FIRST_RUN_EXPERIENCE, true); if (isFirstRun) { vscode.commands.executeCommand(`workbench.action.openWalkthrough`,`microsoft-IsvExpTools.powerplatform-vscode#PowerPage-gettingStarted`, false); context.globalState.update(IS_FIRST_RUN_EXPERIENCE, false); } + + await vscode.workspace.fs.readDirectory(PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext().rootDirectory); + const timeStampBeforeSettingContext = new Date().getTime(); const timeTakenToSetContext = new Date().getTime() - timeStampBeforeSettingContext; sendPerfTelemetry(telemetryEventNames.WEB_EXTENSION_SET_CONTEXT_PERF, timeTakenToSetContext);