Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First time load for file fix and other optimizations #302

Merged
merged 3 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 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,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) {
tyaginidhi marked this conversation as resolved.
Show resolved Hide resolved
throw vscode.FileSystemError.FileNotFound();
}
}
const data = await this._lookupAsFile(uri, false);
return data.data;
}
}
}
return new Uint8Array();
Expand All @@ -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 });
}

Expand Down Expand Up @@ -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();
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