Skip to content

Commit 69fbf2e

Browse files
author
Jaipreet Singh
committed
Switch to GET API; Save the server root respond in a variable
1 parent 42b0415 commit 69fbf2e

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

jupyterlab_git/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def post(self):
445445

446446
class GitServerRootHandler(GitHandler):
447447

448-
def post(self):
448+
def get(self):
449449
# Similar to https://github.com/jupyter/nbdime/blob/master/nbdime/webapp/nb_server_extension.py#L90-L91
450450
self.finish(json.dumps({
451451
"server_root": getattr(self.contents_manager, 'root_dir', None)

src/components/diff/DiffWidget.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function openDiffView(
6868
}
6969
}
7070

71+
let serverRootResultCache = null;
7172
/**
7273
* Gets the path of the file relative to the Jupyter server root. This resolves the server root path after calling
7374
* the `/git/server_root` REST API, and uses the Git repo root and the file path relative to the repo root to resolve
@@ -79,10 +80,15 @@ export async function getRelativeFilePath(
7980
path: string,
8081
topRepoPath: string
8182
): Promise<string> {
82-
const response = await httpGitRequest('/git/server_root', 'POST', {});
83-
const responseData = await response.json();
84-
return PathExt.join(
85-
PathExt.relative(responseData['server_root'], topRepoPath),
86-
path
87-
);
83+
if (serverRootResultCache !== null) {
84+
return serverRootResultCache;
85+
} else {
86+
const response = await httpGitRequest('/git/server_root', 'GET', null);
87+
const responseData = await response.json();
88+
serverRootResultCache = PathExt.join(
89+
PathExt.relative(responseData['server_root'], topRepoPath),
90+
path
91+
);
92+
return serverRootResultCache;
93+
}
8894
}

src/git.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,19 @@ export interface IIdentity {
132132
export function httpGitRequest(
133133
url: string,
134134
method: string,
135-
request: Object
135+
request: Object | null
136136
): Promise<Response> {
137-
let fullRequest = {
138-
method: method,
139-
body: JSON.stringify(request)
140-
};
137+
let fullRequest;
138+
if (request === null) {
139+
fullRequest = {
140+
method: method
141+
};
142+
} else {
143+
fullRequest = {
144+
method: method,
145+
body: JSON.stringify(request)
146+
};
147+
}
141148

142149
let setting = ServerConnection.makeSettings();
143150
let fullUrl = URLExt.join(setting.baseUrl, url);

0 commit comments

Comments
 (0)