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

WorkspaceFileEditOptions add maxSize #111042

Merged
merged 1 commit into from Nov 24, 2020
Merged

Conversation

isidorn
Copy link
Contributor

@isidorn isidorn commented Nov 20, 2020

This PR introduces a maxSize option to the WorkspaceFileEditOptions.
We need to limit how large a file we keep in memory, otherwise this can grow unbounded.

The idea is that Explorer would use this API to limit file sizes that we keep in memory to 5mb.
Corner case: what if the user deletes ten 9mb files. Thea each file is below the limit but will still take up space all together.
I think we can live with this limitation for now, and potentially the UndoRedo service could limit the number of items to 20 always.

fyi @alexdima who also came up with the idea of this approach

@isidorn isidorn added this to the November 2020 milestone Nov 20, 2020
@isidorn isidorn requested a review from jrieken November 20, 2020 17:04
@isidorn isidorn self-assigned this Nov 20, 2020
} catch (err) {
this._logService.critical(err);
}
}

const useTrash = this._fileService.hasCapability(this.oldUri, FileSystemProviderCapabilities.Trash) && this._configurationService.getValue<boolean>('files.enableTrash');
await this._workingCopyFileService.delete([this.oldUri], { useTrash, recursive: this.options.recursive, ...this.undoRedoInfo });
return this._instaService.createInstance(CreateOperation, this.oldUri, this.options, { isUndoing: true }, contents);

if (typeof this.options.maxSize === 'number' && fileContent && (fileContent?.size > this.options.maxSize)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: move to two new private functions so it is reusable and easier to read e.g.

if (this->hasMaxFileSize() && this._doesSizeExceedMax(fileContent)) { return new Noop(); }

} catch (err) {
this._logService.critical(err);
}
}

const useTrash = this._fileService.hasCapability(this.oldUri, FileSystemProviderCapabilities.Trash) && this._configurationService.getValue<boolean>('files.enableTrash');
await this._workingCopyFileService.delete([this.oldUri], { useTrash, recursive: this.options.recursive, ...this.undoRedoInfo });
return this._instaService.createInstance(CreateOperation, this.oldUri, this.options, { isUndoing: true }, contents);

if (typeof this.options.maxSize === 'number' && fileContent && (fileContent?.size > this.options.maxSize)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick: Braces around last condition not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestoin. This way it is more readable for me.

if (!this._undoesCreateOperation && !this.options.folder) {
try {
contents = (await this._fileService.readFile(this.oldUri)).value;
fileContent = (await this._fileService.readFile(this.oldUri));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick: braces around await not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I will change that. Copy / paste error.

Copy link
Member

@jrieken jrieken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look OK to me tho, this doesn't really solve the problem because the accumulation of things (10 little files etc). To circumvent the "restore from trash" problem we could try to move/copy the file that's to be deleted to some tmp-folder

@isidorn
Copy link
Contributor Author

isidorn commented Nov 24, 2020

@jrieken thanks for the review. Yes I mentioned that corner case of 10 little files. I will check with Alex, if he can do a hard limit on item count in the undo redo service. For example 20.
As for the "restore from trash" let's continue the discussion here #111022

@isidorn isidorn merged commit 0ec4063 into master Nov 24, 2020
@isidorn isidorn deleted the isidorn/bulkFileEditsMaxSize branch November 24, 2020 09:09
Copy link

@rheh rheh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT

@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants