Skip to content

Commit

Permalink
Add limit on the file size that can be opened with Open XEL feature (#…
Browse files Browse the repository at this point in the history
…23841)

* Add limit on the file size that can be opened with Open XEL feature

* Add limit on the file size that can be opened and post a notification for large files

* Update wording

* Use FileService interface instead of fs to fix layering rules
  • Loading branch information
SakshiS-harma committed Jul 14, 2023
1 parent 0bf439a commit fd85571
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { IConnectionDialogService } from 'sql/workbench/services/connection/comm
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IFileService } from 'vs/platform/files/common/files';

CommandsRegistry.registerCommand({
id: 'profiler.newProfiler',
Expand Down Expand Up @@ -107,9 +108,10 @@ CommandsRegistry.registerCommand({
const editorService: IEditorService = accessor.get(IEditorService);
const fileDialogService: IFileDialogService = accessor.get(IFileDialogService);
const profilerService: IProfilerService = accessor.get(IProfilerService);
const instantiationService: IInstantiationService = accessor.get(IInstantiationService)
const instantiationService: IInstantiationService = accessor.get(IInstantiationService);
const fileService: IFileService = accessor.get(IFileService);

const result = await profilerService.openFile(fileDialogService, editorService, instantiationService);
const result = await profilerService.openFile(fileDialogService, editorService, instantiationService, fileService);

return result;
}
Expand Down
3 changes: 2 additions & 1 deletion src/sql/workbench/services/profiler/browser/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as azdata from 'azdata';
import { INewProfilerState } from 'sql/workbench/common/editor/profiler/profilerState';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IFileService } from 'vs/platform/files/common/files';

const PROFILER_SERVICE_ID = 'profilerService';
export const IProfilerService = createDecorator<IProfilerService>(PROFILER_SERVICE_ID);
Expand Down Expand Up @@ -148,7 +149,7 @@ export interface IProfilerService {
* @param editorService service to open profiler editor
* @param instantiationService service to create profiler instance
*/
openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService): Promise<boolean>;
openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService, fileService: IFileService): Promise<boolean>;
}

export enum ProfilingSessionType {
Expand Down
18 changes: 17 additions & 1 deletion src/sql/workbench/services/profiler/browser/profilerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ProfilerFilterDialog } from 'sql/workbench/services/profiler/browser/pr
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { ByteSize, IFileService } from 'vs/platform/files/common/files';

class TwoWayMap<T, K> {
private forwardMap: Map<T, K>;
Expand Down Expand Up @@ -303,7 +304,7 @@ export class ProfilerService implements IProfilerService {
await this._configurationService.updateValue(PROFILER_FILTER_SETTINGS, config, ConfigurationTarget.USER);
}

public async openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService): Promise<boolean> {
public async openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService, fileService: IFileService): Promise<boolean> {
const fileURIs = await fileDialogService.showOpenDialog({
filters: [
{
Expand All @@ -317,6 +318,21 @@ export class ProfilerService implements IProfilerService {
if (fileURIs?.length === 1) {
const fileURI = fileURIs[0];

try {
const fileSize = (await fileService.stat(fileURI)).size;
const fileLimitSize = 1 * ByteSize.GB;
const fileOpenWarningSize = 100 * ByteSize.MB;

if (fileSize > fileLimitSize) {
this._notificationService.error(nls.localize('FileTooLarge', "The file is too large to open in profiler. The profiler can open files that are less than 1GB."));
return false;
} else if (fileSize > fileOpenWarningSize) {
this._notificationService.info(nls.localize('LargeFileWait', "Loading the file might take a moment due to the file size."));
}
} catch (err) {
this._notificationService.error(err.message);
}

let profilerInput: ProfilerInput = instantiationService.createInstance(ProfilerInput, undefined, fileURI);
await editorService.openEditor(profilerInput, { pinned: true }, ACTIVE_GROUP);
profilerInput.setConnectionState(false); // Reset connection to be not connected for File session, so that "Start" is not enabled.
Expand Down

0 comments on commit fd85571

Please sign in to comment.