Skip to content

Commit

Permalink
Changes to storage format
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Jun 22, 2023
1 parent a677f9b commit 7898c5d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/kernels/jupyter/connection/serverUriStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class OldStorage {
}
public async getAll(): Promise<IJupyterServerUriEntry[]> {
if (this.lastSavedList) {
return this.lastSavedList;
return this.lastSavedList.then((items) => items.sort((a, b) => b.time - a.time));
}
const promise = async () => {
// List is in the global memento, URIs are in encrypted storage
Expand All @@ -305,7 +305,7 @@ class OldStorage {
return result.filter((item) => !!item) as IJupyterServerUriEntry[];
};
this.lastSavedList = promise();
return this.lastSavedList;
return this.lastSavedList.then((items) => items.sort((a, b) => b.time - a.time));
}
public async getAllRaw(): Promise<IJupyterServerUriEntry[]> {
// List is in the global memento, URIs are in encrypted storage
Expand Down Expand Up @@ -534,7 +534,7 @@ class NewStorage {
.catch(noop));
}
public async getAll(): Promise<IJupyterServerUriEntry[]> {
return this.getAllImpl(true);
return this.getAllImpl(true).then((items) => items.sort((a, b) => b.time - a.time));
}
public async clear(): Promise<void> {
const all = await this.getAllImpl(false);
Expand Down
3 changes: 2 additions & 1 deletion src/platform/common/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class OldCacheCleaner implements IExtensionSyncActivationService {
'JUPYTER_REMOTE_KERNELSPECS_V3',
'JUPYTER_LOCAL_KERNELSPECS_V4',
'LOCAL_KERNEL_SPECS_CACHE_KEY_V_2022_10',
'LOCAL_KERNEL_PYTHON_AND_RELATED_SPECS_CACHE_KEY_V_2022_10'
'LOCAL_KERNEL_PYTHON_AND_RELATED_SPECS_CACHE_KEY_V_2022_10',
'user-jupyter-server-uri-list-v2'
]
.filter((key) => this.globalState.get(key, undefined) !== undefined)
.map((key) => this.globalState.update(key, undefined).then(noop, noop))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { IJupyterPasswordConnectInfo, JupyterPasswordConnect } from './jupyterPa
suite('User Uri Provider', () => {
['Old Password Manager', 'New Password Manager'].forEach((passwordManager) => {
['Old Storage Format', 'New Storage Format'].forEach((storageFormat) => {
suite(storageFormat, () => {
suite(`${passwordManager} - ${storageFormat}`, () => {
const isNewPasswordManager = passwordManager === 'New Password Manager';
const isNewStorageFormat = storageFormat === 'New Storage Format';
let provider: UserJupyterServerUrlProvider;
Expand Down Expand Up @@ -159,6 +159,13 @@ suite('User Uri Provider', () => {
return Promise.resolve();
});

when(
encryptedStorage.store(
Settings.JupyterServerRemoteLaunchService,
'user-jupyter-server-uri-list-v2',
anything()
)
).thenResolve();
when(
encryptedStorage.retrieve(
Settings.JupyterServerRemoteLaunchService,
Expand Down
50 changes: 45 additions & 5 deletions src/standalone/userJupyterServer/userServerUrlProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { validateSelectJupyterURI } from '../../kernels/jupyter/connection/serve
import { Deferred, createDeferred } from '../../platform/common/utils/async';

export const UserJupyterServerUriListKey = 'user-jupyter-server-uri-list';
export const UserJupyterServerUriListKeyV2 = 'user-jupyter-server-uri-list-v2';
export const UserJupyterServerUriListKeyV2 = 'user-jupyter-server-uri-list-version2';
export const UserJupyterServerUriListMementoKey = '_builtin.jupyterServerUrlProvider.uriList';
const GlobalStateUserAllowsInsecureConnections = 'DataScienceAllowInsecureConnections';

Expand Down Expand Up @@ -696,6 +696,40 @@ export class OldStorage {
}
}

type StorageItem = {
handle: string;
uri: string;
displayName: string;
};
function serverToStorageFormat(
servers: {
handle: string;
uri: string;
serverInfo: IJupyterServerUri;
}[]
): StorageItem[] {
return servers.map((s) => ({ handle: s.handle, uri: s.uri, displayName: s.serverInfo.displayName }));
}
function storageFormatToServers(items: StorageItem[]) {
const servers: {
handle: string;
uri: string;
serverInfo: IJupyterServerUri;
}[] = [];
items.forEach((s) => {
const server = parseUri(s.uri);
if (!server) {
return;
}
servers.push({
handle: s.handle,
uri: s.uri,
serverInfo: server
});
});
return servers;
}

export class NewStorage {
private readonly _migrationDone: Deferred<void>;
private updatePromise = Promise.resolve();
Expand All @@ -721,7 +755,13 @@ export class NewStorage {
// Already migrated once before.
return this._migrationDone.resolve();
}

this.encryptedStorage
.store(
Settings.JupyterServerRemoteLaunchService,
'user-jupyter-server-uri-list-v2', // Removed as this storage data is not in the best format.
undefined
)
.catch(noop);
await this.encryptedStorage.store(
Settings.JupyterServerRemoteLaunchService,
UserJupyterServerUriListKeyV2,
Expand All @@ -738,7 +778,7 @@ export class NewStorage {
return [];
}
try {
return JSON.parse(data);
return storageFormatToServers(JSON.parse(data));
} catch {
return [];
}
Expand All @@ -751,7 +791,7 @@ export class NewStorage {
await this.encryptedStorage.store(
Settings.JupyterServerRemoteLaunchService,
UserJupyterServerUriListKeyV2,
JSON.stringify(servers)
JSON.stringify(serverToStorageFormat(servers))
);
})
.catch(noop));
Expand All @@ -763,7 +803,7 @@ export class NewStorage {
return this.encryptedStorage.store(
Settings.JupyterServerRemoteLaunchService,
UserJupyterServerUriListKeyV2,
JSON.stringify(servers)
JSON.stringify(serverToStorageFormat(servers))
);
})
.catch(noop));
Expand Down

0 comments on commit 7898c5d

Please sign in to comment.