Ersei Saggi: 1 Improve performance on rendering files by ~30% 10 files changed, 47 insertions(+), 7 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/47342/mbox | git am -3Learn more about email & git
--- Add explicit dir=auto gitsrht/blueprints/repo.py | 7 +++++ gitsrht/templates/blob.html | 34 +++++++++++++++++++----- gitsrht/templates/clone.html | 2 ++ gitsrht/templates/create.html | 2 ++ gitsrht/templates/send-email-end.html | 2 ++ gitsrht/templates/send-email-review.html | 1 + gitsrht/templates/settings_access.html | 1 + gitsrht/templates/settings_info.html | 2 ++ gitsrht/templates/settings_rename.html | 1 + gitsrht/templates/user.html | 2 ++ 10 files changed, 47 insertions(+), 7 deletions(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index 8828786..8974d2d 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -100,6 +100,12 @@ def _highlight_file(repo, ref, entry, data, blob_id, commit_id): else: return get_highlighted_file("git.sr.ht:git", entry.name, blob_id, data) +def linecounter(count): + out = [] + for i in range(1, count + 1): + out.append('<a href="#L{}" id="L{}">{}\n</a>'.format(i, i, i)) + return "".join(out) + def render_empty_repo(owner, repo, view): origin = cfg("git.sr.ht", "origin") git_user = cfg("git.sr.ht::dispatch", "/usr/bin/gitsrht-keys", "git:git").split(":")[0] @@ -292,6 +298,7 @@ def tree(owner, repo, ref, path): owner=owner, repo=repo, ref=ref, path=path, entry=entry, blob=blob, data=data, commit=orig_commit, highlight_file=_highlight_file, + linecounter=linecounter, editorconfig=editorconfig, markdown=md, force_source=force_source, pygit2=pygit2) tree = git_repo.get(entry.id) diff --git a/gitsrht/templates/blob.html b/gitsrht/templates/blob.html index aabd676..6fe7ad4 100644 --- a/gitsrht/templates/blob.html +++ b/gitsrht/templates/blob.html @@ -73,19 +73,18 @@ pre { {{ markdown }} </div> {% else %} - {% if not blob.is_binary %} + {% if not blob.is_binary and blob.size < 512000 %} <div class="col-md-12 code-view"> + {% autoescape off %} <pre class="ruler"><span>{% for i in range( editorconfig.max_line_length()) %} {% endfor %}</span></pre> - <pre class="lines">{% for line in data.splitlines() %}<a - href="#L{{loop.index}}" - id="L{{loop.index}}" - >{{loop.index}}</a>{% if not loop.last %} -{% endif %}{% endfor %}</pre> + {% set lines = data.splitlines()|length %} + <pre class="lines">{{ linecounter(lines) }}</pre> + {% endautoescape %} {{ highlight_file(repo, ref, entry, data, blob.id.hex, commit.id.hex) }} </div> - {% else %} + {% elif blob.is_binary %} <div class="col-md-12"> <div style="padding: 1rem"> <p> @@ -106,6 +105,27 @@ pre { </p> </div> </div> + {% else %} + <div class="col-md-12"> + <div style="padding: 1rem"> + <p> + <span title="{{ blob.size }} bytes"> + {{humanize.naturalsize(blob.size, + binary=True).replace("Byte", "byte")}} + </span> + large file not shown. + </p> + <p> + <a href="{{url_for("repo.raw_blob", + owner=repo.owner.canonical_name, + repo=repo.name, ref=ref, + path=path_join(*path))}}" + class="btn btn-primary" + rel="nofollow" + >Download {{icon("caret-right")}}</a> + </p> + </div> + </div> {% endif %} {% endif %} </div> diff --git a/gitsrht/templates/clone.html b/gitsrht/templates/clone.html index e1130a9..012aacb 100644 --- a/gitsrht/templates/clone.html +++ b/gitsrht/templates/clone.html @@ -24,6 +24,7 @@ <label for="name">Name</label> <input type="text" + dir="auto" name="name" id="name" class="form-control {{valid.cls("name")}}" @@ -34,6 +35,7 @@ <label for="description">Description</label> <input type="text" + dir="auto" name="description" id="description" class="form-control {{valid.cls("description")}}" diff --git a/gitsrht/templates/create.html b/gitsrht/templates/create.html index 4595173..3128a73 100644 --- a/gitsrht/templates/create.html +++ b/gitsrht/templates/create.html @@ -14,6 +14,7 @@ autofocus {% endif %} type="text" + dir="auto" name="name" id="name" class="form-control {{valid.cls("name")}}" @@ -24,6 +25,7 @@ <label for="description">Description</label> <input type="text" + dir="auto" name="description" id="description" class="form-control {{valid.cls("description")}}" diff --git a/gitsrht/templates/send-email-end.html b/gitsrht/templates/send-email-end.html index 7e77f8b..9af5324 100644 --- a/gitsrht/templates/send-email-end.html +++ b/gitsrht/templates/send-email-end.html @@ -69,6 +69,7 @@ <div class="form-group"> <input type="text" + dir="auto" name="cover_letter_subject" class="form-control {{valid.cls("cover_letter_subject")}}" placeholder="Subject..." @@ -76,6 +77,7 @@ {{valid.summary("cover_letter_subject")}} </div> <textarea + dir="auto" class="form-control {{valid.cls("cover_letter")}}" rows="8" name="cover_letter" diff --git a/gitsrht/templates/send-email-review.html b/gitsrht/templates/send-email-review.html index 28923a3..5e1db6e 100644 --- a/gitsrht/templates/send-email-review.html +++ b/gitsrht/templates/send-email-review.html @@ -50,6 +50,7 @@ <label for="patchset_to">To</label> <input type="text" + dir="auto" name="patchset_to" id="patchset_to" class="form-control {{valid.cls('patchset_to')}}" diff --git a/gitsrht/templates/settings_access.html b/gitsrht/templates/settings_access.html index 99dc5dd..49691fb 100644 --- a/gitsrht/templates/settings_access.html +++ b/gitsrht/templates/settings_access.html @@ -50,6 +50,7 @@ <label for="user">User</label> <input type="text" + dir="auto" class="form-control {{valid.cls("user")}}" id="user" name="user" diff --git a/gitsrht/templates/settings_info.html b/gitsrht/templates/settings_info.html index f11c94b..9c056f8 100644 --- a/gitsrht/templates/settings_info.html +++ b/gitsrht/templates/settings_info.html @@ -16,6 +16,7 @@ </label> <input type="text" + dir="auto" class="form-control" id="name" value="{{repo.name}}" @@ -27,6 +28,7 @@ </label> <input type="text" + dir="auto" class="form-control" id="description" name="description" diff --git a/gitsrht/templates/settings_rename.html b/gitsrht/templates/settings_rename.html index 6ecd05b..de9c79f 100644 --- a/gitsrht/templates/settings_rename.html +++ b/gitsrht/templates/settings_rename.html @@ -12,6 +12,7 @@ </label> <input type="text" + dir="auto" class="form-control {{valid.cls('name')}}" id="name" name="name" diff --git a/gitsrht/templates/user.html b/gitsrht/templates/user.html index 92d5f09..8d3354c 100644 --- a/gitsrht/templates/user.html +++ b/gitsrht/templates/user.html @@ -35,6 +35,7 @@ <input name="search" type="text" + dir="auto" placeholder="Search" class="form-control" value="{{ search if search else "" }}" /> @@ -48,6 +49,7 @@ <input name="search" type="text" + dir="auto" placeholder="Search" class="form-control{% if search_error %} is-invalid{% endif %}" value="{{ search if search else "" }}" /> -- 2.42.0
DO NOT MERGE Superseded by https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/47409