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

feat: cache for FileProperties using Memento #3283

Merged
merged 11 commits into from
Jun 7, 2021

Conversation

maxcamp
Copy link
Contributor

@maxcamp maxcamp commented Jun 3, 2021

What does this PR do?

A wrapper for Memento that can serve as a cache for conflict detection.

What issues does this PR fix or reference?

@W-9258968@, @W-9275211@, @W-9275205@, @W-9275169@

Functionality Before

Mostly new things. The one place where I made edits was in the MockMemento class for unit tests. It now has functionality (implemented with arrays) rather than just method stubs.

Functionality After

PersistentStorageService class which stores LastModifiedDates using FileNames as the keys. It's methods are initialize() and getInstance() which implement a singleton pattern, a get() method, a set() method, and a setMultiple() method which proves to be useful.

@maxcamp maxcamp requested a review from a team as a code owner June 3, 2021 16:35
extensionContext: ExtensionContext
) {
PersistentStorageService.initialize(extensionContext);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need to have a wrapper around the initialize() here? could we call initialize() directly when needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated it to do that in the latest commit

* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { FileProperties } from '@salesforce/source-deploy-retrieve/lib/src/client/types';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we import FileProperties from the top level? ie.

import { FileProperties } from '@salesforce/source-deploy-retrieve';

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, with yesterday's library release you should be able to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would need the extensions to import SDR 2.1.5 which is currently causing me problems, perhaps related to @salesforce/core. Will update this as soon as SDR 2.1.5 is being used


public static getInstance(): PersistentStorageService {
if (!PersistentStorageService.instance) {
throw new Error('Storage should have been initialized upon extension activation');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's localize this message, we can do that by adding the message to this file

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 pointing me to that file. I made an addition, let me know if that works


constructor(setGlobalState: boolean) {
this.telemetryGS = setGlobalState;
}

public get(key: string): any {
private getIndex(key: string): number {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's just use Array.prototype.findIndex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

private static instance?: PersistentStorageService;

private constructor(context: ExtensionContext) {
this.storage = context.workspaceState;
Copy link
Collaborator

@AnanyaJha AnanyaJha Jun 4, 2021

Choose a reason for hiding this comment

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

it looks like we switched over to using the workspaceState storage but based on my local testing, I'm not seeing this storage persist data between sessions. did you find different behavior with the workspaceState storage or are there any drawbacks to using the globalState storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thought was just that using the smaller scope of workspaceState would be preferable if it did in fact work. I saw the data persist for simple cases but did not thoroughly test it, so I have switched back to global in the latest commit.

@maxcamp maxcamp merged commit 6904a9a into develop Jun 7, 2021
@maxcamp maxcamp deleted the intern/conflict-detection branch June 7, 2021 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants