Skip to content

Commit

Permalink
Performance improvment (OctoLinker#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbuck authored Jan 24, 2020
1 parent bda435e commit 93d8516
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 673 deletions.
282 changes: 0 additions & 282 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"puppeteer": "^2.0.0",
"recursive-readdir": "^2.2.2",
"sinon": "^8.0.1",
"string.prototype.matchall": "^4.0.0",
"style-loader": "^1.0.0",
"web-ext": "^4.0.0",
"web-ext-submit": "^3.2.1",
Expand Down
25 changes: 19 additions & 6 deletions packages/blob-reader/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,45 @@ async function fetchRaw({ user, repo, ref, path }) {
}

export default class Blob {
constructor({ el, path, lines, blobType, branch = undefined }) {
constructor({ el, path, lines, type, branch = undefined }) {
this.el = el;
this.path = path;
this.lines = lines;
this.branch = branch;
this.blobType = blobType; // one of: diffLeft, diffRight, snippet, full

if (this.lines.length > 5000) {
this.lines = this.lines.slice(0, 500);
}

this.type = type; // one of: diffLeft, diffRight, snippet, full, gist
}

lineSelector(lineNumber) {
if (this.isDiff) {
const side = this.blobType === 'diffLeft' ? 'L' : 'R';
const side = this.type === 'diffLeft' ? 'L' : 'R';

// The double selector is needed to avoid situations where the first line
// is the chunk information like: @@ -0,0 +1 @@
return `[id$='${side}${lineNumber}'][data-line-number='${lineNumber}']`;
}

if (this.blobType === 'snippet') {
if (this.isSnippet) {
return 'pre';
}

if (this.type === 'gist') {
return `[id$='LC${lineNumber}']`;
}

return `#LC${lineNumber}`;
}

get isDiff() {
return ['diffLeft', 'diffRight'].includes(this.blobType);
return ['diffLeft', 'diffRight'].includes(this.type);
}

get isSnippet() {
return this.type === 'snippet';
}

toString() {
Expand All @@ -68,7 +81,7 @@ export default class Blob {
this.lines = await fetchRaw({
user,
repo,
ref: this.branch || branch, // this.branch is given when blobType is diffLeft
ref: this.branch || branch, // this.branch is given when type is diffLeft
path,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/blob-reader/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,4 @@ function readLines(el) {
.filter(line => !!line);
}

export { getPath, getBlobWrapper, readLines, getParentSha };
export { getPath, getBlobWrapper, readLines, getParentSha, isGist };
Loading

0 comments on commit 93d8516

Please sign in to comment.