From c0b8d5e70b84a8c9b3fb54aa7029a5c39c3f1a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nidhi=20Tyagi=20=F0=9F=8C=9F=F0=9F=90=87=F0=9F=8C=B4?= =?UTF-8?q?=E2=9D=84=EF=B8=8F?= Date: Thu, 29 Sep 2022 16:52:36 +0530 Subject: [PATCH 1/2] FIrst time load for file fix and other optimizations --- src/web/client/common/fileSystemProvider.ts | 44 +++++++++----------- src/web/client/common/remoteFetchProvider.ts | 11 +++-- src/web/client/extension.ts | 1 + 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..eaf95d20 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,20 @@ 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(); + + if (PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext().defaultFileUri !== uri) { + throw vscode.FileSystemError.FileNotFound(); + } + } + const data = await this._lookupAsFile(uri, false); + return data.data; + } } } return new Uint8Array(); @@ -122,14 +132,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 +241,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 df46c426..a68ccba5 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.window.showTextDocument(vscode.Uri.parse(fileUri)); } } @@ -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 c8e51a8e..40c280d7 100644 --- a/src/web/client/extension.ts +++ b/src/web/client/extension.ts @@ -62,6 +62,7 @@ export function activate(context: vscode.ExtensionContext): void { switch (appName) { case 'portal': { sendExtensionInitQueryParametersTelemetry(searchParams); + await vscode.workspace.fs.readDirectory(PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext().rootDirectory); const timeStampBeforeSettingContext = new Date().getTime(); const timeTakenToSetContext = new Date().getTime() - timeStampBeforeSettingContext; From 9be0411a96536f00c258d63aa1a23c9c02c7e4d1 Mon Sep 17 00:00:00 2001 From: tyaginidhi Date: Fri, 30 Sep 2022 08:59:41 +0530 Subject: [PATCH 2/2] Update fileSystemProvider.ts --- src/web/client/common/fileSystemProvider.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/web/client/common/fileSystemProvider.ts b/src/web/client/common/fileSystemProvider.ts index eaf95d20..db211fb6 100644 --- a/src/web/client/common/fileSystemProvider.ts +++ b/src/web/client/common/fileSystemProvider.ts @@ -102,13 +102,10 @@ export class PortalsFS implements vscode.FileSystemProvider { && uri.toString().includes(rootDirectory.toString())) { if (PathHasEntityFolderName(uri.toString())) { await this._loadFromDataverseToVFS(); - - if (PowerPlatformExtensionContextManager.getPowerPlatformExtensionContext().defaultFileUri !== uri) { - throw vscode.FileSystemError.FileNotFound(); - } + + const data = await this._lookupAsFile(uri, false); + return data.data; } - const data = await this._lookupAsFile(uri, false); - return data.data; } } }