Skip to content

Commit

Permalink
First time load for file fix and other optimizations (#302)
Browse files Browse the repository at this point in the history
* FIrst time load for file fix and other optimizations

* Update fileSystemProvider.ts
  • Loading branch information
tyaginidhi authored Sep 30, 2022
1 parent bf8ec80 commit 4592786
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
41 changes: 16 additions & 25 deletions src/web/client/common/fileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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();
Expand All @@ -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 });
}

Expand Down Expand Up @@ -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();
Expand Down
11 changes: 5 additions & 6 deletions src/web/client/common/remoteFetchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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});
}
}
Expand All @@ -174,9 +174,8 @@ async function createVirtualFile(
) {
const saveEntityDetails = new SaveEntityDetails(entityId, entity, saveDataAttribute, useBase64Encoding, mimeType);
const dataMap: Map<string, SaveEntityDetails> = 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 });
}
4 changes: 4 additions & 0 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4592786

Please sign in to comment.