Skip to content

frontend: Store file source in cache #202

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

Merged
merged 2 commits into from
Sep 27, 2019
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
23 changes: 18 additions & 5 deletions frontend/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,25 @@ function monitorOptions() {
}

// hgmo.
const sourceCache = {};
export async function getSource(file, revision) {
if (!revision || revision === "latest") {
revision = "tip";
}
const url = `https://hg.mozilla.org/mozilla-central/raw-file/${revision}/${file}`;

export async function getSource(file) {
const response = await fetch(
`https://hg.mozilla.org/mozilla-central/raw-file/tip/${file}`
);
return response.text();
let source = cacheGet(sourceCache, url);
if (source) {
return source;
}

const response = await fetch(url);
source = await response.text();
source = source.split("\n");

cacheSet(sourceCache, url, source);

return source;
}

// Filtering.
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async function showDirectory(dir, revision, files) {
}

async function showFile(file, revision) {
const source = await getSource(file.path);
const source = await getSource(file.path, revision);

let language;
if (file.path.endsWith("cpp") || file.path.endsWith("h")) {
Expand All @@ -150,7 +150,7 @@ async function showFile(file, revision) {
navbar: buildNavbar(file.path, revision),
revision: revision || REV_LATEST,
language,
lines: source.split("\n").map((line, nb) => {
lines: source.map((line, nb) => {
const coverage = file.coverage[nb];
let cssClass = "";
let hits = null;
Expand Down