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

[Port] Add limit on the file size that can be opened with Open XEL feature #23876

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading