~sircmpwn/hg.sr.ht

173187e7a0d169d05f0f9e78f828a62fcedeb189 — Ludovic Chabant 1 year, 4 months ago e3a2283 0.4.0
Improve performance and pagination of /heads

Don't paginate only tags, but also branches and bookmarks. Then, grab
commit information only for those that make it to the UI. This fixes the
performance issues as we query the revlog only for the 10 heads being
shown, not potentially hundreds of them.

Fixes #7 and #8
1 files changed, 11 insertions(+), 8 deletions(-)

M hgsrht/blueprints/repo.py
M hgsrht/blueprints/repo.py => hgsrht/blueprints/repo.py +11 -8
@@ 499,27 499,30 @@ def heads(owner, repo):
    owner, repo = get_repo_or_redir(owner, repo)
    with HgRepository(repo.path) as hg_repo:
        branches = hg_repo.client.branches()
        branches = [get_branch_info(owner, repo, hg_repo, b) for b in branches]
        bmarks, cur_bmark = hg_repo.client.bookmarks()
        bmarks = [get_bookmark_info(owner, repo, hg_repo, bm) for bm in bmarks]
        bmarks, _ = hg_repo.client.bookmarks()
        tags = hg_repo.client.tags()
        tags = [get_tag_info(owner, repo, hg_repo, t) for t in tags]

        results_per_page = 10
        page = request.args.get("page")
        total_results = len(tags)
        total_results = max(len(tags), len(branches))
        total_pages = total_results // results_per_page + 1
        if total_results % results_per_page == 0:
            total_pages -= 1
        if page is not None:
            try:
                page = int(page) - 1
                tags = tags[page*results_per_page:page*results_per_page+results_per_page]
                page = max(0, int(page) - 1)
            except:
                page = 0
        else:
            page = 0
            tags = tags[:results_per_page]
        offset = page * results_per_page
        branches = branches[offset:offset+results_per_page]
        bmarks = bmarks[offset:offset+results_per_page]
        tags = tags[offset:offset+results_per_page]

        branches = [get_branch_info(owner, repo, hg_repo, b) for b in branches]
        bmarks = [get_bookmark_info(owner, repo, hg_repo, bm) for bm in bmarks]
        tags = [get_tag_info(owner, repo, hg_repo, t) for t in tags]

        return render_template("heads.html", view="heads",
            owner=owner, repo=repo,